Skip to content

Instantly share code, notes, and snippets.

@DOsinga
Last active April 8, 2018 23:09
Show Gist options
  • Save DOsinga/89641a10ac400901ecbced40ef5d365b to your computer and use it in GitHub Desktop.
Save DOsinga/89641a10ac400901ecbced40ef5d365b to your computer and use it in GitHub Desktop.
from datetime import date, timedelta
from collections import Counter
# all the dates that fit the equation:
dates = [*filter(lambda d:d.year - 2000 == d.month * d.day, [date(2001, 1, 1) + timedelta(i) for i in range(36158)])]
# total events is number of dates:
print(len(dates))
# Counter.most_common is the year that occurs most:
print(Counter(d.year for d in dates).most_common(1)[0])
# Counter value == 1 -> years that occur least
print([*filter(lambda x: x[1] == 1, Counter(d.year for d in dates).most_common())])
# Longest period without an attack is the difference between two consequetive items:
print(max([(d2 - d1, d1, d2, ) for d1, d2 in zip(dates[:-1], dates[1:])]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment