DECLARE SUB permute (a$)
CLS
DEFDBL A-Z
FOR y = 1 TO 9
used(y) = 1
FOR m = 1 TO 9
IF used(m) = 0 THEN
used(m) = 1
FOR o = 0 TO 9
IF used(o) = 0 THEN
used(o) = 1
FOR u = 0 TO 9
IF used(u) = 0 THEN
used(u) = 1
FOR e = 0 TO 9
IF used(e) = 0 THEN
used(e) = 1
FOR n = 0 TO 9
IF used(n) = 0 THEN
used(n) = 1
you = 100 * y + 10 * o + u
me = 10 * m + e
money = 10000 * m + 1000 * o + 100 * n + 10 * e + y
IF you * me = money THEN
PRINT y; o; u, m; e, m; o; n; e; y
ys = y: os = o: us = u: ms = m: es = e: ns = n
ct = ct + 1
END IF
used(n) = 0
END IF
NEXT
used(e) = 0
END IF
NEXT
used(u) = 0
END IF
NEXT
used(o) = 0
END IF
NEXT
used(m) = 0
END IF
NEXT
used(y) = 0
NEXT
PRINT ct
a$ = LTRIM$(STR$(ys)) + LTRIM$(STR$(os)) + LTRIM$(STR$(us)) + LTRIM$(STR$(ms)) + LTRIM$(STR$(es)) + LTRIM$(STR$(ns))
h$ = a$
DO
a = VAL(MID$(a$, 1, 1))
b = VAL(MID$(a$, 2, 1))
c = VAL(MID$(a$, 3, 1))
d = VAL(MID$(a$, 4, 1))
e = VAL(MID$(a$, 5, 1))
f = VAL(MID$(a$, 6, 1))
s = (a + b) * (c + d) * (e + f)
IF s > max THEN
max = s
PRINT a; b; c; d; e; f, s
END IF
permute a$
LOOP UNTIL a$ = h$
finds the solution to the alphametic:
Y O U M E M O N E Y
8 1 4 2 7 2 1 9 7 8
and the best total from these digits:
A B C D E F (A+B)*(C+D)*(E+F)
8 2 1 9 4 7 1100
|
Posted by Charlie
on 2014-01-14 17:49:20 |