t h eb
ee r i
s o k
Use simple substitution code (letters to digits)
to get a 3x3 magic square.
Rem: eb=10*e+b
DECLARE SUB permute (a$)
CLS
a$ = "0123456789": h$ = a$
DO
t = VAL(MID$(a$, 1, 1))
h = VAL(MID$(a$, 2, 1))
e = VAL(MID$(a$, 3, 1))
b = VAL(MID$(a$, 4, 1))
r = VAL(MID$(a$, 5, 1))
i = VAL(MID$(a$, 6, 1))
s = VAL(MID$(a$, 7, 1))
o = VAL(MID$(a$, 8, 1))
k = VAL(MID$(a$, 9, 1))
eb = 10 * e + b
ee = 11 * e
IF t + h + eb = ee + r + i AND s + o + k = ee + r + i THEN
IF t + ee + s = h + r + o AND h + r + o = eb + i + k THEN
IF t + r + k = eb + r + s AND eb + r + s = t + h + eb AND t + h + eb = h + r + o THEN
PRINT t; h; eb
PRINT ee; r; i
PRINT s; o; k
PRINT
END IF
END IF
END IF
permute a$
LOOP UNTIL a$ = h$
finds three potential solutions, but in two of them the letter "e" represents zero and thus leads to leading zeros, so only the middle solution below is in keeping with the spirit of the puzzle:
5 6 01
00 4 8
7 2 3
6 5 10
11 7 3
4 9 8
7 2 03
00 4 8
5 6 1
I've placed the leading zeros manually as the program prints only the single digits in those cases.
|
Posted by Charlie
on 2012-04-06 13:44:50 |