Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Uncategorized category for Next Birthday by Elena_Korljukova
from typing import Dict, Tuple
from datetime import date
Date = Tuple[int, int, int]
def next_birthday(today: Date, birthdates: Dict[str, Date]) -> Tuple[int, Dict[str, int]]:
a = [(i, birthdates[i], today[0] if birthdates[i][1:] == (2, 29) and today[1:] == (3,1) or birthdates[i][1] > today[1] or birthdates[i][1] == today[1] and birthdates[i][2] >= today[2] else today[0] + 1) for i in birthdates]
a = [(i[0], (i[1][0], 3, 1), i[2]) if i[1][1:] == (2, 29) and (i[1][0] % 4 != 0 or i[2] % 4 != 0) else i for i in a]
d = [(date(x[2], x[1][1], x[1][2]) - date(*today)).days for x in a]
day = sorted(d)[0]
a = [a[i] for i in range(len(a)) if d[i] == day]
return (day, {i[0] : i[2] - i[1][0] for i in a})
if __name__ == '__main__':
FAMILY = {
'Brian': (1967, 5, 31),
'Léna': (1970, 10, 3),
'Philippe': (1991, 6, 15),
'Yasmine': (1996, 2, 29),
'Emma': (2000, 12, 25),
}
TESTS = [
((2020, 9, 8), (25, {'Léna': 50})),
((2021, 10, 4), (82, {'Emma': 21})),
((2022, 3, 1), (0, {'Yasmine': 26})),
]
for nb, (day, answer) in enumerate(TESTS, 1):
user_result = tuple(next_birthday(day, FAMILY.copy()))
if user_result != answer:
print(f'You failed the test #{nb}.')
print(f'Your result: {user_result}')
print(f'Right result: {answer}')
break
else:
print('Well done! Click on "Check" for real tests.')
Oct. 18, 2020