Enigmatic Code

Programming Enigma Puzzles

Enigma 1574: Doubly square dates

From New Scientist #2737, 5th December 2009 [link]

4 April 2001 was the first doubly square date of the century because whether written in the order day.month.year or in the order month.day.year (in each instance with two digits for each element) it comes out as 04.04.01, and 40401 is 2012.

Still with two digits for each element, there are some doubly square dates for which the square that comes from the order day.month.year is not the same as the square that comes from the order month.day.year. This is the case for each of the next two doubly square dates after 4 April 2001. What are those two dates (in the same form as 4 April 2001)?

[enigma1574]

Advertisements

One response to “Enigma 1574: Doubly square dates

  1. jimrandell 13 February 2012 at 9:04 am

    The following Python program runs in 50ms.

    from enigma import irange, is_square, sprintf, printf
    
    def solve():
      n = 0
      for year in irange(0, 99):
        for month in irange(1, 12):
          for day in irange(1, 31):
            # consider the d-m-y format
            dmy = int(sprintf("{day:02d}{month:02d}{year:02d}"))
            r1 = is_square(dmy)
            if not r1: continue
            # now conside the m-d-y format
            mdy = int(sprintf("{month:02d}{day:02d}{year:02d}"))
            r2 = is_square(mdy)
            if not r2: continue
            printf("[{day:02d}.{month:02d}.{year:02d}] {r1}^2 = {dmy}, {r2}^2 = {mdy}")
            n += 1
            if n == 3: return
    
    solve()
    

    Solution: The dates are 12 April 2009 and 4 December 2009.

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: