Posts Tagged dates

Permutable Dates

Gregorus seems to have already posted about this, but I can post my solution. We came up with the puzzle of finding the 8-digit number (with zeros allowed at the beginning) which has the largest possible number of permutations that are possible dates. Some numbers like 99,999,999 don’t have any. Others like 01,234,567 have a lot (starting with 01/23/4567, and most of those digits can be swapped around).

I wrote my program in the Bash shell language and it has two lines.

Line One:

perl -e 'useĀ  Date::Manip; my $d = ParseDate("01/01/0001");while(UnixDate("%Y") < 10000) {print UnixDate($d,"%m%d%Y\n"); $d = DateCalc($d, "+ 1 day");}' >> all-dates.txt


This just makes all the possible dates, one day at a time. Perl’s Date::Manip module is notoriously slow, and it took almost two hours to make all 3,652,059 dates in this millenium (not quite actually: the last year of the millenium has a five digit year). As for the delay, I rationalized that I had optimized my code for “programmer time”.

Line Two:

perl -ne 'print join("", sort (split("", $_)))' all-dates.txt | sort | uniq -c | sort -n


This sorts the digits in each date to make ordered digit clusters, then orders the clusters of digits by how many times they appear.

The results? 00,123,578 will make 2,472 dates! Of course, it is a 20,160-way tie, because any permutation of 00,123,578, such as 57,800,123 will make the same 2,472 dates.

Unfortunately, I can’t make any dates near to us from 00,123,578. The closest I can get on both sides is 07/08/2135 and 03/20/1875. Can anyone do better?

Comments (2)