Skip to content

Instantly share code, notes, and snippets.

@kangkyu
Last active August 29, 2015 14:27
Show Gist options
  • Save kangkyu/083901e4cb54e918929f to your computer and use it in GitHub Desktop.
Save kangkyu/083901e4cb54e918929f to your computer and use it in GitHub Desktop.
# Write a method leap_year?. It should accept a year value from the user, check whether it's a leap year, and then return true or false. Note: a century year, like 1900 and 2000, is a leap year only if it is divisible by 400.
def leap_year?(year)
year % 400 == 0 || year % 100 != 0 && year % 4 == 0
end
[1998, 1996, 2000, 2100].each do |year|
minutes = if leap_year?(year)
366 * 24 * 60
else
365 * 24 * 60
end
puts "#{minutes} minutes in year #{year}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment