Teaser 2902: Birthdays 2018
From The Sunday Times, 6th May 2018 [link] [link]
Several friends have birthdays on different days in 2018.
Replacing A by 1, B by 2, C by 3 … and Z by 26, each month and day can be replaced by a sequence of numbers. Every birthday is given numerically by day, date and month, as described above. For each friend, there is just one number common to each of their 3 sets of numbers. The number of friends is the largest possible.
How many friends are there and what is the largest number of clear days between consecutive birthdays?
[teaser2902]




Jim Randell 12:45 pm on 1 July 2019 Permalink |
The puzzle text is not completely clear, and allows several interpretations.
I interpreted it as follows:
A date, such as Friday 25th May 2018, is translated into a sequence of numbers as follows:
The “day of month” always provides a sequence with a single number in it, and this number must also appear in the “day name” sequence and the “month name” sequence (which are created by translating the letters to numbers). Furthermore it must be the only number that is shared between the translated sequences.
In the example 25=Y occurs in FRIDAY and also in MAY, but it is not the only letter in common A=1 also occurs.
Using this interpretation we find there are only four dates that meet the requirements. And we then look for the longest gap between consecutive dates in this set.
This Python program runs in 83ms.
Run: [ @repl.it ]
import datetime from enigma import (tuples, printf) # days (0-indexed) days = ( 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY' ) # months (1-indexed) months = ( None, 'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER' ) # turn letters into numbers letters = "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" l2n = lambda s: tuple(letters.index(x) for x in s) year = 2018 # year inc = datetime.timedelta(1) # 1 day increment # consider days in the required year d = datetime.date(year, 1, 1) n = 0 bd = list() while d.year == year: (day, date, month) = (l2n(days[d.weekday()]), d.day, l2n(months[d.month])) # find letters in both day and month s = set(day).intersection(month) if len(s) == 1 and date in s: # maybe just [[ date in s ]] n += 1 printf("n={n}: {d} -> {wday} {date} {wmonth} -> {day} ({date}={wdate}) {month}", wday=days[d.weekday()], wdate=letters[date], wmonth=months[d.month]) bd.append(d) d += inc # number of birthdays n = len(bd) # find the maximum delta deltas = list((b - a).days - 1 for (a, b) in tuples(bd, 2)) printf("{n} values, max delta = {m} days (deltas={deltas})", m=max(deltas))Solution: There are 4 friends. The longest gap between consecutive dates is 81 days.
The 4 dates are:
The longest gap between these dates is 81 non-birthday days between [3] and [4].
However, if we’re looking at “the maximum number of consecutive non-birthday days in 2018” there is a longer run from 1st January to 31st March, which is 90 days. (The run from 16th October to 31st December is 77 days).
And the puzzle just asks for the longest gap between birthdays, and once we have fixed the dates we can see that the gap between birthday [4] and the next occurrence of birthday [1] (in 2019) is 167 days, and this gap would be 1 day longer if a leap year is involved. So the longest possible gap between birthdays is 168 days.
LikeLike