There are five lumberjacks. When they go into the woods every day, each lumberjack wears a different colored cap and chops down only one kind of tree.
Lumberjacks: Abe, Ben, Cal, Dan, Frank.
Trees: elm, maple, pine, spruce, oak.
Cap colors: blue, red, yellow, black, green.
1. Cal wears a red cap.
2. Ben chops down elm trees.
3. The oak cutter does not wear the yellow cap.
4. The wearer of the green cap cuts down spruce trees.
5. Dan does not wear the yellow cap.
6. Frank wears the blue cap.
7. Dan chops down maple trees.
8. The lumberjack with blue cap chops down pines.
From the clues given above, match each lumberjack to his cap and the tree.
DECLARE SUB permute (a$)
CLS
tree$ = "empso": htree$ = tree$
DO
goodt = 1
IF MID$(tree$, 2, 1) <> "e" THEN goodt = 0
IF MID$(tree$, 4, 1) <> "m" THEN goodt = 0
IF goodt THEN
cap$ = "brykg": hcap$ = cap$
DO
goodc = 1
IF MID$(cap$, 3, 1) <> "r" THEN goodc = 0
ix = INSTR(tree$, "o")
IF MID$(cap$, ix, 1) = "y" THEN goodc = 0
ix = INSTR(tree$, "s")
IF MID$(cap$, ix, 1) <> "g" THEN goodc = 0
IF MID$(cap$, 4, 1) = "y" THEN goodc = 0
IF MID$(cap$, 5, 1) <> "b" THEN goodc = 0
ix = INSTR(tree$, "p")
IF MID$(cap$, ix, 1) <> "b" THEN goodc = 0
IF goodc THEN
FOR i = 1 TO 5
SELECT CASE i
CASE 1: PRINT "Abe wears ";
CASE 2: PRINT "Ben wears ";
CASE 3: PRINT "Cal wears ";
CASE 4: PRINT "Dan wears ";
CASE 5: PRINT "Frank wears ";
END SELECT
c$ = MID$(cap$, i, 1)
SELECT CASE c$
CASE "b": PRINT "blue and chops ";
CASE "r": PRINT "red and chops ";
CASE "y": PRINT "yellow and chops ";
CASE "k": PRINT "black and chops ";
CASE "g": PRINT "green and chops ";
END SELECT
t$ = MID$(tree$, i, 1)
SELECT CASE t$
CASE "e": PRINT "elm."
CASE "m": PRINT "maple."
CASE "p": PRINT "pine."
CASE "s": PRINT "spruce."
CASE "o": PRINT "oak."
END SELECT
NEXT i
END IF
permute cap$
LOOP UNTIL hcap$ = cap$
END IF
permute tree$
LOOP UNTIL tree$ = htree$
finds
Abe wears green and chops spruce.
Ben wears yellow and chops elm.
Cal wears red and chops oak.
Dan wears black and chops maple.
Frank wears blue and chops pine.

Posted by Charlie
on 20120717 17:06:40 