Skip to content

Instantly share code, notes, and snippets.

@mfpiccolo
Last active December 11, 2015 05:48
Show Gist options
  • Save mfpiccolo/4554548 to your computer and use it in GitHub Desktop.
Save mfpiccolo/4554548 to your computer and use it in GitHub Desktop.
You can enter in a year and the code will tell you if it is a leap year or not.
def leap_year?(year)
if year % 4 == 0 && year % 100 != 0
year == true
elsif year % 400 == 0
year = true
else
year = false
end
end
puts "'#{leap_year?(1983)}' should equal 'false'"
puts "'#{leap_year?(1992)}' should equal 'true'"
puts "'#{leap_year?(1900)}' should equal 'false'"
puts "'#{leap_year?(2000)}' should equal 'true'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment