# Why doesn't this work?

6 people go to the movies, and they 6 tickets for seats that are in one row. AB want to sit next to each other, CD don't. How many ways can they sit down? :

DIM names(1 TO 6)
CLS
count = 0
FOR i = 1 TO 6
names(i) = i + 64
NEXT
FOR a = 1 TO 6
FOR b = 1 TO 6
IF b <> a THEN
FOR c = 1 TO 6
IF c <> a AND c <> b THEN
FOR d = 1 TO 6
IF d <> a AND d <> b AND d <> c THEN
FOR e = 1 TO 6
IF e <> a AND e <> b AND e <> c AND e <> d THEN
FOR f = 1 TO 6
IF f <> a AND f <> b AND f <> c AND f <> d AND f <> e THEN
text\$ = CHR\$(a + 64) + CHR\$(b + 64) + CHR\$(c + 64) + CHR\$(d + 64) + CHR\$(e + 64) + CHR\$(f + 64)
GOSUB analyse

END IF
NEXT
END IF
NEXT
END IF
NEXT
END IF
NEXT
END IF
NEXT
NEXT

PRINT count: END
analyse:
ABright = 0
FOR x = 1 TO 5
IF RIGHT\$(LEFT\$(text\$, x), 1) = "A" AND RIGHT\$(LEFT\$(text\$, x + 1), 1) = "B" THEN ABright = 1: GOTO 1
IF RIGHT\$(LEFT\$(text\$, x), 1) = "B" AND RIGHT\$(LEFT\$(text\$, x + 1), 1) = "A" THEN ABright = 1: GOTO 1
NEXT
1
CDright = 0
FOR x = 1 TO 5
IF RIGHT\$(LEFT\$(text\$, x), 1) = "C" AND RIGHT\$(LEFT\$(text\$, x + 1), 1) = "D" THEN CDright = 1: GOTO 2
IF RIGHT\$(LEFT\$(text\$, x), 1) = "D" AND RIGHT\$(LEFT\$(text\$, x + 1), 1) = "C" THEN CDright = 1: GOTO 2
NEXT
2
IF ABright = 1 AND CDright = 0 THEN count = count + 1: COLOR 9: PRINT text\$: 'SLEEP 1
RETURN

Posted on Jan 2, 2008, 9:43 AM

Respond to this message