# A magic square filled with consecutive primes

In 1988 Martin Gardner offered a \$100 prize for the first person to produce a magic square filled with consecutive primes. Later that year, Harry Nelson found 22 solutions using a Cray computer.

 1,480,028,201 1,480,028,129 1,480,028,183 1,480,028,153 1,480,028,171 1,480,028,189 1,480,028,159 1,480,028,213 1,480,028,141

Gardner said that the square above is “almost certainly the one with the lowest constant possible for such a square.”

It’s easy to verify that the numbers above are consecutive primes. Here’s a little Python code for the job. The function `nextprime(x, i)` gives the next `i` primes after `x`. We call the function with `x` equal to one less than the smallest entry in the square and it prints out all the entries.

```from sympy import nextprime
for i in range(1,10):
print( nextprime(148028128, i) )
```

If you’re looking for more than a challenge, verify whether Gardner’s assertion was correct that the square above uses the smallest possible set of consecutive primes.

By the way, assuming Harry Nelson’s Cray was the Y-MP model that came out in 1988, here are its specs according to Wikipedia:

The Y-MP could be equipped with two, four or eight vector processors, with two functional units each and a clock cycle time of 6 ns (167 MHz). Peak performance was thus 333 megaflops per processor. Main memory comprised 128, 256 or 512 MB of SRAM.

Related posts:

Magic squares from a knight’s tour and a king’s tour.

For daily tweets on algebra and other math, follow @AlgebraFact on Twitter.

## 7 thoughts on “A magic square filled with consecutive primes”

1. Duncan Reynolds

Very cool! There’s a typo in your Python – should be 1480028128 not 1480082128 🙂

2. Thanks!

3. By my reckoning, the python code to verify the numbers are consecutive primes should be

from sympy import nextprime
for i in range(1,10):
print( nextprime(1480028128, i) )

1. 82128 becomes 28128
2. ‘range’ returns 1 .. 9 instead of 0 .. 8

4. Thanks. I’ve fixed these errors.

5. Hugh Myers

You just pick on me with your blogs because you know I’m a sucker for primes 🙁 Great (if small) blog—kudos. I’d forgotten the Gardener article, thanks for the memory. BTW, did you notice that the latest Cray is upgrading to the latest INTEL chip. I’m sure that this is some kind of irony, but I’m not sure just what and how…

6. If you normalize a magic square to make the lowest number 0, you’re left with 8 unique values.

It should not be too hard to calculate all solutions of a reasonable size, then match rolling sets of consecutive primes against them.