Each of the capital letters in bold in this 3x3 grid is to be substituted by a different digit from 1 to 9 such that :
- Each of A, C, G and I is even, and:
- The sum of the digits in each of the four 2x2 subgrids is equal.
A B C
D E F
G H I
Disregarding the rotations and reflections, how many distinct solutions are there?
I used the following basic code
as was done in the previous version of the question I used a<c<g
and a<i to prevent rotations and reflections
CLS 0
OPEN ".\output.txt" FOR OUTPUT AS #1
cnt = 0
FOR a = 1 TO 9
FOR b = 1 TO 9
IF b <> a THEN
FOR c = 1 TO 9
IF c > a AND c <> b THEN
FOR d = 1 TO 9
IF d <> a AND d <> b AND d <> c THEN
FOR e = 1 TO 9
IF e <> a AND e <> b AND e <> c AND e <> d THEN
s = a + b + d + e
FOR f = 1 TO 9
IF f <> a AND f <> b AND f <> c AND f <> d AND f <> e AND b + c + e + f = s THEN
FOR g = 1 TO 9
IF g <> b AND g > c AND g <> d AND g <> e AND g <> f THEN
FOR h = 1 TO 9
IF h <> a AND h <> b AND h <> c AND h <> d AND h <> e AND h <> f AND h <> g AND d + e + g + h = s THEN
FOR i = 1 TO 9
IF i > a AND i <> b AND i <> c AND i <> d AND i <> e AND i <> f AND i <> g AND i <> h AND e + f + h + i = s THEN
cnt = cnt + 1
PRINT #1, a; b; c
PRINT #1, d; e; f
PRINT #1, g; h; i
PRINT #1,
END IF
NEXT i
END IF
NEXT h
END IF
NEXT g
END IF
NEXT f
END IF
NEXT e
END IF
NEXT d
END IF
NEXT c
END IF
NEXT b
NEXT a
PRINT #1, cnt
CLOSE #1
to get the following 47 solutions
1 5 3
9 8 7
4 2 6
1 6 2
8 9 7
4 3 5
1 6 2
9 7 8
4 3 5
1 7 2
9 4 8
5 3 6
1 7 2
9 6 8
3 5 4
1 7 4
8 3 5
6 2 9
1 7 4
9 2 6
5 3 8
1 8 2
5 9 4
6 3 7
1 8 3
6 5 4
7 2 9
1 8 3
9 2 7
4 5 6
1 8 4
5 7 2
6 3 9
1 9 2
5 6 4
7 3 8
1 9 2
6 4 5
7 3 8
1 9 2
6 8 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