Skip to content

Instantly share code, notes, and snippets.

@mejiaro
Created May 1, 2015 21:55
Show Gist options
  • Save mejiaro/112c6ce4244195a6621c to your computer and use it in GitHub Desktop.
Save mejiaro/112c6ce4244195a6621c to your computer and use it in GitHub Desktop.
Calculates leap years between two years
def divisible_by_4?(year)
return true if year % 4 == 0
end
def divisible_by_100?(year)
return true if year % 100 == 0
end
def divisible_by_400?(year)
return true if year % 400 == 0
end
puts 'Please type starting year.'
year1 = gets.to_i
puts 'Thank you. Please type ending year.'
year2 = gets.to_i
while year1 <= year2
if divisible_by_4?(year1)
puts year1.to_s + ' is a leap year'
elsif !divisible_by_100?(year1) && divisible_by_400?(year1)
puts year1.to_s + ' is a leap year'
else
end
year1 = year1 + 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment