# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1489: Even digit squares

From New Scientist #2651, 12th April 2008

Harry, Tom and I were looking to find 5-digit perfect squares that used only even digits. 0 counted as an even digit but could not be used as a leading digit or a final digit.

We each found a different set of three such squares, and in each of our sets each of the five even digits was used a different number of times.

My set had two squares in common with Harry’s set and two squares in common with Tom’s set.

What were the three squares in my set?

[enigma1489]

### One response to “Enigma 1489: Even digit squares”

1. Jim Randell 19 November 2012 at 10:26 am

The following Python program runs in 37ms.

```from itertools import combinations
from enigma import irange, printf

# even digits
evens = set('02468')

# find 5-dgit squares, using only even digits
# 0 is not allowed as a final digit
# 142 = ceil(sqrt(20000))
# 298 = floor(sqrt(88888))
squares = set()
for i in irange(142, 298):
s = str(i * i)
if s[-1] == '0' or not evens.issuperset(s): continue

# find sets of 3 squares
# where each even digit is used a different number of times
s3 = set()
for (x, y, z) in combinations(squares, 3):
# check the digit counts are all different
if len(set((x + y + z).count(c) for c in evens)) != 5: continue