# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1641: 3 × 3 = 1

From New Scientist #2807, 9th April 2011 [link]

Joe printed and cut out nine 3 by 3 cardboard magic squares. The nine squares used all the numbers from 1 to 81.

For a square to be magic, the sums of the numbers in each row, each column and each diagonal must all be the same. This sum is called the magic constant.

Joe gave the nine magic squares to Penny and suggested she arrange them to make a 9 by 9 magic square and tell him the magic constant of the 3 by 3 square she placed in the middle.

What was the magic constant?

[enigma1641]

### One response to “Enigma 1641: 3 × 3 = 1”

1. jimrandell 7 December 2011 at 10:23 pm

The following Python code runs in 200ms.

```# 9x9 square sum is 369
# so: a+b+c = d+e+f = g+h+i = a+d+g = b+e+h = c+f+i = 369
# constants could be:
# 15, 42, 69, 96, 123, 150, 177, 204, 231

from itertools import permutations

c = 369
for s in permutations(range(15, 232, 27), 9):
if sum(s[0:3]) != c: continue
if sum(s[3:6]) != c: continue
# if sum(s[6:9]) != c: continue
if s + s + s != c: continue
if s + s + s != c: continue
# if s + s + s != c: continue
if s + s + s != c: continue
if s + s + s != c: continue
print(s, s)
```

Solution: The magic constant on the central 3×3 square is 123.

This site uses Akismet to reduce spam. Learn how your comment data is processed.