Brainteaser 1568: Back to the future
From The Sunday Times, 27th September 1992 [link]
Many dates, such as my birthday 27th September 1972, are palindromic when written down in the form day/month/year without breaks, my birthday being 2791972.
What about palindromic dates in the millennium beginning on 1st January 2000?
(a) How many palindromic dates will there be in this millennium?
(b) Of these, which two are closest together?
The text above is taken from the book Brainteasers (2002), and is different from the originally published puzzle, which is reproduced below:
With another palindromic date occurring on Tuesday (29.9.1992) I am reminded of a Teaser I set last year in which readers were asked to find the longest sequence of consecutive non-palindromic dates in the next 200 years. Here’s another idea:
Assuming the standard numerical format of a date as day.month.year with the year as a four-figure number and with no zeros to start the day or month, find the two palindromic dates in the future which are closest together.
[teaser1568]







Jim Randell 12:44 pm on 9 May 2019 Permalink |
This Python program considers dates from 1-1-2000 to 31-12-2999. It runs in 780ms.
Run: [ @replit ]
from datetime import (date, timedelta) from enigma import (repeat, inc, concat, tuples, Accumulator, printf) # record palindromic dates from 2000 - 2999 ds = list() for d in repeat(inc(timedelta(days=1)), date(2000, 1, 1)): if not (d.year < 3000): break s = concat(d.day, d.month, d.year) if s == s[::-1]: ds.append(d) printf("[{n} palindromic dates]", n=len(ds)) # find the two dates closest together r = Accumulator(fn=min) r.accumulate_data_from((b - a, (a, b)) for (a, b) in tuples(ds, 2)) # output solution (t, (a, b)) = (r.value, r.data) printf("{a.day}-{a.month}-{a.year} -> {b.day}-{b.month}-{b.year} ({t.days} days)")Solution: (a) There are 323 palindromic dates. (b) The closest pair is: 23-2-2232 and 2-3-2232 (8 days apart).
Pleasingly the number of palindromic dates is itself a palindrome.
If we extend the date range to the year 9999 there are 2107 more palindromic dates (assuming the calendar remains the same). And the closest two are:
And if we extend the current calendar backwards to year 1 we can manage even better:
LikeLike
Lise Andreasen 12:20 am on 8 May 2024 Permalink |
Does your algorithm count 1112111 (to give an example) as one or 2 dates? 1/11/2111 and 11/1/2111.
LikeLike
Lise Andreasen 12:30 am on 8 May 2024 Permalink |
Oh, never mind. Figured it out.
LikeLike
Lise Andreasen 12:34 am on 8 May 2024 Permalink |
It’s possible to count the variations.
There are 81 dates of the form a/b/22ba.
There are 27 dates of the form a/bc/2cba.
There are 192 dates of the form ab/c/2cba.
There are 22 dates of the form ab/12/21ba.
Neat algorithm though. 👍🏻
LikeLike
Jim Randell 10:26 am on 8 May 2024 Permalink |
I don’t know if it is a typo, but these numbers don’t add up to 323.
I found there should 193 dates of the form ab/c/2cba. (Or maybe you forgot: 29/2/2292).
LikeLike
Lise Andreasen 12:53 pm on 8 May 2024 Permalink |
It was a typo. And it’s probably also a remnant of me getting that leap year date wrong the first time through.
LikeLike