## Riddler Express

The year is 2000, and an arithmetical anarchist group has an idea. For the next 100 years, it will vandalize a famous landmark whenever the year (in two-digit form, for example this year is “18”) is the product of the month and date (i.e. month × date = year, in the MM/DD/YY format).

A few questions about the lawless ensuing century: How many attacks will happen between the beginning of 2001 and the end of 2099? What year will see the most vandalism? The least? What will be the longest gap between attacks?

### Solution

```
from datetime import date, timedelta
= {
days_in_month 1:31,
2:28,
3:31,
4:30,
5:31,
6:30,
7:31,
8:31,
9:30,
10:31,
11:30,
12:31
}
= {}
attacks_by_year = date(2001,1,1)
date_last_attack = 0
max_gap for year in range(1, 100):
= 0
attacks_by_year[year] for month in days_in_month.keys():
= days_in_month[month]
days if year % 4 == 0 and month == 2:
+= 1
days for day in range(1, days+1):
if month*day == year:
+= 1
attacks_by_year[year] = date(2000+year, month, day)
date_latest_attack = date_latest_attack - date_last_attack
gap if gap.days >= max_gap:
= gap.days
max_gap = date_latest_attack
date_last_attack
print("Max gap in days between attacks:", max_gap-1)
print("Attacks by year: ", attacks_by_year)
print("Total number of attacks: ", sum(attacks_by_year.values()))
print("Year of max attacks: ", max(attacks_by_year.items(),
= lambda x: x[1])) key
```

The year with the maximum number of attacks is \(2024\) with \(7\) attacks in total. There are a number of years with no attacks at all. The total number of attacks in all years is \(212\). The maximum gap in days between two attacks is \(1096\).