Guest User

Cheryl

a guest
Oct 4th, 2024
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. from collections import Counter
  2.  
  3. def birthday(months):
  4.     # eliminate months with a unique day (albert knows that bernard doesn't know the date)
  5.     c = Counter(day for month in months for day in month)
  6.     possible_months = [(i, month) for i, month in enumerate(months) if all(c[day] > 1 for day in month)]
  7.    
  8.     # if any remaining month has a unique day, return that (bernard now knows the date)
  9.     c = Counter(day for _, month in possible_months for day in month)
  10.     for i, month in possible_months:
  11.         possible_dates = [day for day in month if c[day] == 1]
  12.         if len(possible_dates) == 1:
  13.             return (i, possible_dates[0])
  14.  
Advertisement
Add Comment
Please, Sign In to add comment