1 3 2 4 9 5 8 6 7
g h i j k o l m n
DECLARE FUNCTION try! (p1!, p2!, p3!, p4!, p5!, p6!, p7!, p8!, p9!, h!)
DIM taken(50)
FOR g = 1 TO 9 STEP 2
taken(g) = 1
FOR h = 1 TO 9
IF taken(h) = 0 THEN
taken(h) = 1
FOR i = 1 TO 9
IF taken(i) = 0 THEN
taken(i) = 1
FOR j = 1 TO 9
IF taken(j) = 0 THEN
taken(j) = 1
IF (h + j) MOD 2 = 1 THEN
k = h + i + j
IF k < 10 AND taken(k) = 0 THEN
taken(k) = 1
FOR l = 1 TO 9
IF taken(l) = 0 THEN
taken(l) = 1
FOR m = 1 TO 9
IF taken(m) = 0 THEN
taken(m) = 1
IF (l + m) MOD 2 = 0 THEN
n = (l + m) / 2
IF taken(n) = 0 AND (l + n) MOD 2 = 1 THEN
taken(n) = 1
FOR o = 1 TO 9
IF taken(o) = 0 THEN
ord$ = \\"g hijk lmn o\\"
IF try(g, h, i, j, k, l, m, n, o, 2) THEN GOSUB reportIt
ord$ = \\"g hijk o lmn\\"
IF try(g, h, i, j, k, o, l, m, n, 2) THEN GOSUB reportIt
ord$ = \\"g lmn hijk o\\"
IF try(g, l, m, n, h, i, j, k, o, 5) THEN GOSUB reportIt
ord$ = \\"g lmn o hijk\\"
IF try(g, l, m, n, o, h, i, j, k, 6) THEN GOSUB reportIt
ord$ = \\"g o hijk lmn\\"
IF try(g, o, h, i, j, k, l, m, n, 3) THEN GOSUB reportIt
ord$ = \\"g o lmn hijk\\"
IF try(g, o, l, m, n, h, i, j, k, 6) THEN GOSUB reportIt
END IF
NEXT
taken(n) = 0
END IF
END IF
taken(m) = 0
END IF
NEXT m
taken(l) = 0
END IF
NEXT l
taken(k) = 0
END IF
END IF
taken(j) = 0
END IF
NEXT j
taken(i) = 0
END IF
NEXT i
taken(h) = 0
END IF
NEXT h
taken(g) = 0
NEXT
PRINT ct
END
reportIt:
PRINT ord$
ct = ct + 1
RETURN
FUNCTION try (p1, p2, p3, p4, p5, p6, p7, p8, p9, h)
DIM p(9)
p(1) = p1
p(2) = p2
p(3) = p3
p(4) = p4
p(5) = p5
p(6) = p6
p(7) = p7
p(8) = p8
p(9) = p9
good = 1
IF (p2 + p9) MOD 2 = 1 THEN good = 0
IF (p8 + p1) MOD 2 = 0 THEN good = 0
IF good THEN
FOR i = 1 TO 7
IF (p(i) + p(i + 2)) MOD 2 = 0 THEN good = 0: EXIT FOR
NEXT
END IF
IF good THEN
tot = 0
IF p1 = p2 + p9 THEN tot = 1
IF p9 = p8 + p1 THEN tot = tot + 1
FOR i = 2 TO 8
IF p(i) = p(i - 1) + p(i + 1) THEN tot = tot + 1
NEXT
IF p(h) <> tot THEN good = 0
END IF
IF good THEN
FOR i = 1 TO 9
PRINT p(i);
NEXT
PRINT
END IF
try = good
END FUNCTION
resulting in:
1 3 2 4 9 5 8 6 7
g hijk o lmn
1 solution
(program designed to start with the gray, fortuitously the card with the "1")
From Enigma No. 1460, by Susan Denham, New Scientist, 15 September 2007 |