Skip to content

Instantly share code, notes, and snippets.

@keithtom
Forked from stomatocode/gist:5333048
Last active December 15, 2015 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithtom/5333069 to your computer and use it in GitHub Desktop.
Save keithtom/5333069 to your computer and use it in GitHub Desktop.
def leap_year?(year)
if year % 4 == 0
puts "I am divisible by 4!"
true
elsif year % 100 == 0
puts "I am divisible by 100!"
false
elsif year % 100 == 0 && year % 400 == 0
puts "I am divisible by 100 and 400!"
true
elsif year % 4 == 0 && year % 100 == 0 && !(year % 400 == 0)
puts "I am divisible by 4, 100 but not 400"
false
else
puts "The else condition"
false
end
end
# got these values from the spec
puts leap_year?(4)
puts leap_year?(100)
puts leap_year?(400)
puts leap_year?(3)
puts leap_year?(1988)
puts leap_year?(1989)
puts leap_year?(1998)
puts leap_year?(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment