Skip to content

Instantly share code, notes, and snippets.

@lordhumunguz
Created March 7, 2013 20:07
Show Gist options
  • Save lordhumunguz/5111328 to your computer and use it in GitHub Desktop.
Save lordhumunguz/5111328 to your computer and use it in GitHub Desktop.
Leap year method
#Leap years are divisible by 4 (like 1992 and 1996).
#There is an exception, though, and an exception to the exception:
#if a year is divisible by 100, it's not a leap year (like 1900),
#unless it is also divisible by 400 (like the year 2000).
def leap_year? (year)
if year%100 == 0 && year%400 == 0
puts "Leap Year!"
elsif year%4 == 0 && year%100 != 0
puts "Leap Year!"
else
puts "Not Leap Year!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment