+---------+-------+
| 1 2 5 9 | R |
+---------+-------+
| 1 3 8 9 | R B |
+---------+-------+
| 1 3 5 7 | B B |
+---------+-------+
| 4 3 9 7 | B B |
+---------+-------+
Each of the rows in the table given above indicates an attempt to find out the secret number. Each try has, in the column to the right, the letters R and B.
Each R indicates that this number has one digit in common with the secret number, but in a different position.
Each B indicates that this number has one digit in common with the secret number in the same position.
Determine the secret number.
DATA 1259,r,1389,rb,1357,bb,4397,bb
FOR i = 1 TO 4
READ n$(i), a$(i)
NEXT
FOR a = 0 TO 9
ag$ = LTRIM$(STR$(a))
FOR b = 0 TO 9
ab$ = ag$ + LTRIM$(STR$(b))
FOR c = 0 TO 9
abc$ = ab$ + LTRIM$(STR$(c))
FOR d = 0 TO 9
abcd$ = abc$ + LTRIM$(STR$(d))
good = 1
FOR i = 1 TO 4
t$ = abcd$
resp$ = ""
FOR p = 1 TO 4
IF MID$(t$, p, 1) = MID$(n$(i), p, 1) THEN
resp$ = resp$ + "b": MID$(t$, p, 1) = " "
END IF
NEXT p
FOR p = 1 TO 4
IF INSTR(n$(i), MID$(t$, p, 1)) > 0 THEN
resp$ = "r" + resp$
END IF
NEXT p
IF resp$ <> a$(i) THEN good = 0: EXIT FOR
NEXT
IF good THEN PRINT a; b; c; d
NEXT
NEXT
NEXT
NEXT
finds
8 3 2 7
|
Posted by Charlie
on 2013-08-20 14:40:20 |