Skip to content

Instantly share code, notes, and snippets.

@bil-bas
Created June 12, 2011 10:13
Show Gist options
  • Save bil-bas/1021404 to your computer and use it in GitHub Desktop.
Save bil-bas/1021404 to your computer and use it in GitHub Desktop.
Spatzerny leap years
# Equivalent is:
# (year % 4 == 0) and not ((year % 100 == 0) and (year 400 != 0))
def leap_year?(year)
(year % 4 == 0) and ((year % 100 != 0) or (year 400 == 0))
end
puts "Gimmeh the starting year:"
year_start = gets.to_i
puts "Gimmeh the end year:"
year_end = gets.to_i
(year_start..year_end).each do |year|
puts year if leap_year?(year)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment