Enigmatic Code

Programming Enigma Puzzles

Enigma 1498: Cubic date

From New Scientist #2660, 14th June 2008

14 June 08 if written as 14.06.08 (day’s number.month.year, with two digits allocated to each) is a cubic date because 140608 is the cube of 52. If it is written as 14.06.08 it is obvious the day’s number precedes the month. But a date may also be written as month.day’s number.year, with two digits allocated to each: 42875 (the cube of 35) written as 04.28.75 must represent 28 April 75. Some cubes can represent two different cubic dates: 10648 (the cube of 22) written as 01.06.48 could represent 1 June 48 or 6 January 48.

Harry and Tom know that I have written down a cubic date like 14 June 08, but have not been told whether to be cubic it has the day’s number or the month placed first. Harry knows what the month is, and that enables him to deduce the date with certainty. Tom knows what the day’s number is, but that does not enable him to deduce the date.

What is the date? Give your answer in the form of 14 June 08.



One response to “Enigma 1498: Cubic date

  1. Jim Randell 30 October 2012 at 6:20 pm

    The following Python program runs in 35ms. I don’t explicitly deal with leap years (but then neither does the problem).

    from collections import defaultdict
    from enigma import irange, printf
    # map month numbers to names (for the solution, 1-indexed)
    MONTH = ( None,
      'January', 'February', 'March', 'April', 'May', 'June',
      'July', 'August', 'September', 'October', 'November', 'December'
    # map month numbers to number of days (ignoring leap years, 1-indexed)
    DAYS  = ( None, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 )
    # consider 5 and 6 digit cubes
    r = defaultdict(list)
    for i in irange(22, 99):
      s = str(i ** 3)
      # split into digits: aa.bb.cc
      (aa, bb, cc) = (int(n) for n in (s[-6:-4], s[-4:-2], s[-2:]))
      # a date can be expressed dd.mm.yy or mm.dd.yy
      if ((0 < bb <= 12 and 0 < aa <= DAYS[bb]) or (0 < aa <= 12 and 0 < bb <= DAYS[aa])):
        r[aa].append((s, bb))
        r[bb].append((s, aa))
    # the date we're looking for is ambiguous by day
    for (dd, v) in r.items():
      if len(v) < 2: continue
      # but unambiguous by month
      for (s, mm) in v:
        if mm > 12 or len(r[mm]) > 1: continue
        printf("{dd} {m} {yy}", m=MONTH[mm], yy=s[-2:])

    Solution: 11 September 25.

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: