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?



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
      s3.add((x, y, z))
    # D has one set
    for D in s3:
      d = set(D)
      # find sets that share two of the squares
      TH = list(s for s in s3 if len(d.intersection(s)) == 2)
      # we need there to be (at least) two (for T and H)
      if len(TH) < 2: continue
      printf("D={D} [T/H={TH}]")

    Solution: The three squares in Dick’s set are 26244, 68644, 88804.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: