Created
August 10, 2012 05:36
-
-
Save lune-sta/3311369 to your computer and use it in GitHub Desktop.
Project Euler 19
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
y = 1901 | |
m = 1 | |
d = 1 | |
w = 1 # 0..6 -> Sun..Sat | |
count = 0 | |
def m31? (m) | |
[1,3,5,7,8,10,12].each do |i| | |
if m == i | |
return true | |
end | |
end | |
return false | |
end | |
def yleap? (y) | |
if y % 400 == 0 | |
return true | |
elsif y % 100 ==0 | |
return false | |
elsif y % 4 == 0 | |
return true | |
else | |
return false | |
end | |
end | |
loop do | |
w = w == 6 ? w = 0 : w += 1 | |
if d == 1 && w == 0 | |
count += 1 | |
end | |
d += 1 | |
if y == 2000 && m == 12 | |
break | |
end | |
if d == 32 || (d == 31 && !m31?(m)) || (d == 30 && m == 2) || (d == 29 && m == 2 && !yleap?(y)) | |
d = 1 | |
m += 1 | |
end | |
if m == 13 | |
m = 1 | |
y += 1 | |
end | |
end | |
puts count # 171 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment