DECLARE SUB permute (a$)
CLS
a$ = "1234567890": h$ = a$
DO
w = VAL(MID$(a$, 1, 1))
e = VAL(MID$(a$, 2, 1))
d = VAL(MID$(a$, 3, 1))
t = VAL(MID$(a$, 4, 1))
a = VAL(MID$(a$, 5, 1))
b = VAL(MID$(a$, 6, 1))
p = VAL(MID$(a$, 7, 1))
i = VAL(MID$(a$, 8, 1))
n = VAL(MID$(a$, 9, 1))
wedv = VAL(LEFT$(a$, 3))
tabv = VAL(MID$(a$, 4, 3))
pinv = VAL(MID$(a$, 7, 3))
x..y = wedv + tabv + pinv
x = x..y \ 1000: y = x..y MOD 10
IF (x = 1 AND y = 2 OR x = 2 AND y = 1) THEN
IF w <> 0 AND t <> 0 AND p <> 0 AND d <> 0 AND b <> 0 AND n <> 0 THEN
dew = 100 * d + 10 * e + w
bat = 100 * b + 10 * a + t
nip = 100 * n + 10 * i + p
y..x = dew + bat + nip
y = y..x \ 1000: x = y..x MOD 10
IF x = 1 AND y = 2 OR x = 2 AND y = 1 THEN
xy$ = LTRIM$(STR$(x..y))
yx$ = LTRIM$(STR$(y..x))
good = 1
FOR j = 1 TO 4
IF MID$(xy$, j, 1) <> MID$(yx$, 5 - j, 1) THEN good = 0: EXIT FOR
NEXT j
IF good THEN
ct = ct + 1
bad = 0
IF w = 1 OR t = 1 OR p = 1 OR d = 1 OR b = 1 OR n = 1 THEN bad = 1
IF w = 2 OR t = 2 OR p = 2 OR d = 2 OR b = 2 OR n = 2 THEN bad = 1
' IF w = 3 OR t = 3 OR p = 3 OR d = 3 OR b = 3 OR n = 3 THEN bad = 1
IF bad THEN PRINT a$, xy$, yx$
END IF
END IF
END IF
END IF
permute a$
LOOP UNTIL a$ = h$
PRINT ct
(The permute subroutine appears in the solution to the Permutations puzzle on this site.)
does indeed find 864 solutions to the alphametics taken simultaneously.
However we do get solutions of the type
675+308+249 = 1232
576+803+942 = 2321
where P = 2 = Y.
Perhaps what is meant is that in all these solutions none of W, T, P, D, B or N, nor even E, A or I, is a 1, so that X and Y can't both be one of those digits, even though one can be.
|
Posted by Charlie
on 2013-11-22 12:56:19 |