All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Logic
Top four people (Posted on 2008-10-18) Difficulty: 2 of 5
Top four people and their occupation were listed in a magazine.
 place   1st name    surname    occupation
-------------------------------------------
   1      Isaac      Newtune    welder
   2      Albert     Eyeline    gardener
   3      Marie      Curious    cleaner
   4      Paul       Darling    bricklayer
-------------------------------------------
However, only one entry in each of the three righmost columns was correctly positioned. The following facts were true:
(1) Albert was two places above the bricklayer.
(2) Darling was one place below Paul.
(3) Curious was two places below the welder.

Find the first name, surname and occupation for each position.

See The Solution Submitted by pcbouhid    
Rating: 2.5000 (2 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 2 of 3 |
 1 Paul    Newtune   cleaner
 2 Albert  Darling   welder
 3 Isaac   Eyeline   gardener
 4 Marie   Curious   bricklayer

DECLARE SUB permute (a$)
DECLARE FUNCTION matchCt! (a$, b$)
name1$ = "iamp": name2$ = "necd": occ$ = "wgcb"
hName1$ = "iamp": hName2$ = "necd": hOcc$ = "wgcb"
DATA Isaac,Albert,Marie,Paul
DATA Newtune,Eyeline,Curious,Darling
DATA welder,gardener,cleaner,bricklayer
FOR i = 1 TO 4: READ n1$(i): NEXT
FOR i = 1 TO 4: READ n2$(i): NEXT
FOR i = 1 TO 4: READ oc$(i): NEXT
PRINT
DO
 IF matchCt(name1$, hName1$) = 1 THEN
DO
 IF matchCt(name2$, hName2$) = 1 THEN
DO
 IF matchCt(occ$, hOcc$) = 1 THEN
  good = 1
  ix1 = INSTR(name1$, "a"): ix2 = INSTR(occ$, "b")
  IF ix2 <> ix1 + 2 THEN good = 0
  ix1 = INSTR(name1$, "p"): ix2 = INSTR(name2$, "d")
  IF ix2 <> ix1 + 1 THEN good = 0
  ix1 = INSTR(name2$, "c"): ix2 = INSTR(occ$, "w")
  IF ix2 <> ix1 - 2 THEN good = 0
  IF good THEN
   FOR place = 1 TO 4
    PRINT place;
    PRINT n1$(INSTR(hName1$, MID$(name1$, place, 1))); "  ";
    PRINT TAB(12); n2$(INSTR(hName2$, MID$(name2$, place, 1))); "  ";
    PRINT TAB(22); oc$(INSTR(hOcc$, MID$(occ$, place, 1))); "  "
   NEXT
  END IF
 END IF
 permute occ$
LOOP UNTIL occ$ = hOcc$
 END IF
 permute name2$
LOOP UNTIL name2$ = hName2$
 END IF
 permute name1$
LOOP UNTIL name1$ = hName1$

FUNCTION matchCt (a$, b$)
 ct = 0
 FOR i = 1 TO LEN(a$)
  IF MID$(a$, i, 1) = MID$(b$, i, 1) THEN ct = ct + 1
 NEXT
 matchCt = ct
END FUNCTION


  Posted by Charlie on 2008-10-18 15:14:19
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (2)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2017 by Animus Pactum Consulting. All rights reserved. Privacy Information