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

 The 8 cards (Posted on 2009-01-31)
You have 8 cards (pieces of paper) numbered from 1 to 8. The first 4 are all white, and the last 4 are all black. On each one is written:

#1: The next two cards are black.
#2: The next two cards are of different colors.
#3: The previous card has the same color as the next.
#4: There are the same number of black cards before and after this one.
#5: The previous card is of the same color as the next.
#6: The previous card is white.
#7: The next two cards are of the same color.
#8: The previous card is black.

Arrange the 8 cards in a row so that all the sentences result truthfully.

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

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution | Comment 1 of 9

DECLARE SUB permute (a\$)
CLS
numb\$ = "12345678": numbH\$ = numb\$
DO
clr\$ = ""
FOR i = 1 TO 8
IF MID\$(numb\$, i, 1) <= "4" THEN clr\$ = clr\$ + "w":  ELSE clr\$ = clr\$ + "b"
NEXT
ix = INSTR(numb\$, "1"): v\$ = MID\$(clr\$, ix, 3)
IF v\$ = "wbb" OR v\$ = "bbb" THEN
ix = INSTR(numb\$, "2"): v\$ = MID\$(clr\$, ix, 3)
IF v\$ = "wbw" OR v\$ = "wwb" OR v\$ = "bbw" OR v\$ = "bwb" THEN

ix = INSTR(numb\$, "3")
IF ix > 1 THEN
v\$ = MID\$(clr\$, ix - 1, 3)
IF v\$ = "bwb" OR v\$ = "www" OR v\$ = "bbb" OR v\$ = "wbw" THEN
ix = INSTR(numb\$, "4"): bCt1 = 0: bCt2 = 0
FOR iPos = 1 TO 8
IF MID\$(clr\$, iPos, 1) = "b" THEN
IF iPos < ix THEN bCt1 = bCt1 + 1
IF iPos > ix THEN bCt2 = bCt2 + 1
END IF
NEXT iPos
IF bCt1 = bCt2 THEN

ix = INSTR(numb\$, "5")
IF ix > 1 THEN
v\$ = MID\$(clr\$, ix - 1, 3)
IF v\$ = "bbb" OR v\$ = "wbw" OR v\$ = "bwb" OR v\$ = "www" THEN
ix = INSTR(numb\$, "6")
IF ix > 1 THEN
IF MID\$(clr\$, ix - 1, 2) = "wb" OR MID\$(clr\$, ix - 1, 2) = "ww" THEN

ix = INSTR(numb\$, "7")
v\$ = MID\$(clr\$, ix, 3)
IF v\$ = "bbb" OR v\$ = "bww" OR v\$ = "wbb" OR v\$ = "www" THEN
ix = INSTR(numb\$, "8")
IF ix > 1 THEN
IF MID\$(clr\$, ix - 1, 2) = "bb" OR MID\$(clr\$, ix - 1, 2) = "bw" THEN
PRINT : PRINT clr\$: PRINT numb\$: PRINT
END IF
END IF
END IF

END IF
END IF
END IF
END IF

END IF
END IF
END IF

END IF
END IF
permute numb\$
LOOP UNTIL numb\$ = numbH\$

finds

`wbwbwwbb25374168`

 Posted by Charlie on 2009-01-31 17:58:27

 Search: Search body:
Forums (0)