### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 177,972 hits

Advertisements

Programming Enigma Puzzles

18 April 2012

Posted by on **From New Scientist #2700, 21st March 2009** [link]

A school class consisted of Elsa, John, Marty, Paul, Sheila, Smack and Suzy. I explained to them that a 3-by-3 magic square consists of an array of nine different numbers such that any row, column or diagonal has the same sum. I asked each of them to make one using only whole numbers between 1 and 26 inclusive.

They each succeeded and I then asked them to replace their numbers by letters using A=1, B=2, C=3 and so on. Amazingly, in every case but one the child’s magic square contained the letters of their name.

Whose did not?

[enigma1537]

Advertisements

%d bloggers like this:

Here’s my original Perl solution. It runs in 1.8s.

Solution:Paul’s magic square does not contain the letters of his name.And here’s a Python solution. It runs in 45ms.

It makes use of the fact that the centre number is a 3 x 3 magic square is one third the magic constant (see my comments in the

Enigma 1680posts for proof of this). I’ve also included a newirange()function (inclusive range) in theenigma.pylibrary, for those cases when you want a range that includes both endpoints.