Enigmatic Code

Programming Enigma Puzzles

Enigma 1668: Square dates

From New Scientist #2834, 15th October 2011 [link] [link]

4 December 2009 is the most recent date that qualifies as a perfect square date when written as day, month, year with two digits for each element, that is as 04.12.09: 41209 is the square of 203.

Using the same format, what is the only instance in any century of two consecutive dates that are both perfect squares?

[enigma1668]

One response to “Enigma 1668: Square dates

  1. Jim Randell 2 December 2011 at 5:36 pm

    The following Python program runs in 91ms.

    from enigma import is_square
    
    def fmt(dd, mm, yy):
      return '{dd:02d}.{mm:02d}.{yy:02d}'.format(dd=dd, mm=mm, yy=yy)
    
    prev = None
    for yy in range(100):
      for mm in range(1, 13):
        for dd in range(1, 32):
          n = dd * 10000 + mm * 100 + yy
          if is_square(n):
            if prev:
              print(fmt(*prev), fmt(dd, mm, yy))
            prev = (dd, mm, yy)
          else:
            prev = None
    

    Solution: The two dates are 01.10.25 and 02.10.25.

Leave a Comment

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