Created
December 14, 2011 14:06
-
-
Save agentfin/1476685 to your computer and use it in GitHub Desktop.
Leap year checker, chapter 7 of Chris Pine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Leap Years | |
# well, we need a year. | |
puts 'Pick a year any year!' | |
year = gets.chomp | |
# then we need to see if it is divisible by 4 | |
# and not 100 | |
# unless it's also divisible by 400 | |
# could use % which is 'modulus' and divides the number but | |
# returns just the remainder | |
# instead, comparing floats and integers | |
# first remove those not divisible by 4 | |
if (year.to_f / 4) != (year.to_i / 4) | |
puts 'FUCK THAT.' | |
elsif | |
# then get rid of those divisible by 100 | |
if (year.to_f / 100) != (year.to_i / 100) | |
puts year + ' was so rad!' | |
elsif | |
# . . . except for the ones divisible by 400 | |
if (year.to_f / 400) != (year.to_i / 400) | |
puts 'Nice try.' | |
else | |
puts 'That\'s the best year ever! Let\'s go back to ' + year + '.' | |
end | |
end | |
puts 'Yeah, ' + year + ' was pretty primo.' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment