Created
March 17, 2009 11:54
-
-
Save oscardelben/80492 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
months_table = | |
{ | |
1 => 0, | |
2 => 3, | |
3 => 3, | |
4 => 6, | |
5 => 1, | |
6 => 4, | |
7 => 6, | |
8 => 2, | |
9 => 5, | |
10 => 0, | |
11 => 3, | |
12 => 5 | |
} | |
leap_table = | |
{ | |
1 => 6, | |
2 => 2, | |
3 => 3, | |
4 => 6, | |
5 => 1, | |
6 => 4, | |
7 => 6, | |
8 => 2, | |
9 => 5, | |
10 => 0, | |
11 => 3, | |
12 => 5 | |
} | |
sundays = 0 | |
first_day = 0 | |
# From 1901 to 1999 | |
1.upto(99) do |year| | |
1.upto(12) do |month| | |
if year % 4 == 0 # leap | |
table = leap_table | |
else | |
table = months_table | |
end | |
if (first_day + year + (year / 4) + table[month] + 1) % 7 == 0 | |
sundays += 1 | |
end | |
end | |
end | |
# 2000 which starts with 6 | |
first_day = 6 | |
year = 0 | |
1.upto(12) do |month| | |
if (first_day + year + (year / 4) + leap_table[month] + 1) % 7 == 0 | |
sundays += 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment