Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - from collections import Counter
- def birthday(months):
- # eliminate months with a unique day (albert knows that bernard doesn't know the date)
- c = Counter(day for month in months for day in month)
- possible_months = [(i, month) for i, month in enumerate(months) if all(c[day] > 1 for day in month)]
- # if any remaining month has a unique day, return that (bernard now knows the date)
- c = Counter(day for _, month in possible_months for day in month)
- for i, month in possible_months:
- possible_dates = [day for day in month if c[day] == 1]
- if len(possible_dates) == 1:
- return (i, possible_dates[0])
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment                    
                 
                    