Created
December 24, 2018 15:44
-
-
Save jesboat/3e471d5e41d014731c41d4a19c4c1971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ") | |
days_normal = map(int, "31 28 31 30 31 30 31 31 30 31 30 31".split(" ")) | |
days_leap = map(int, "31 29 31 30 31 30 31 31 30 31 30 31".split(" ")) | |
assert len(months) == 12 | |
assert len(days_normal) == 12 | |
assert len(days_normal) == 12 | |
assert sum(days_normal) == 365 | |
assert sum(days_leap) == 366 | |
for ymod400 in range(0, 400): # [0, 1, ..., 399] | |
for monthnum, monthname in enumerate(months): | |
isleap = ymod400 % 4 == 0 and (ymod400 % 100 != 0 or ymod400 % 400 == 0) | |
num_days = (days_leap if isleap else days_normal)[monthnum] | |
for daynum in range(1, num_days + 1): # [1, 2, ..., num_days] | |
print("%s %d in a year $y mod 400 = %d$" % (monthname, daynum, ymod400)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment