Created
May 27, 2012 20:38
-
-
Save MrBri/2815837 to your computer and use it in GitHub Desktop.
Challenge 1 in the forums from Ruby Core at rubylearning.org
This file contains 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
def age(sec) | |
years_float = sec.to_f / 60 / 60 / 24 / 365 | |
years_int = sec / 60 / 60 / 24 / 365 | |
months = (years_float - years_int) * 12 | |
puts "I'm #{years_int} years and #{months.to_i} months old." | |
end | |
age 979000000 | |
age 2158493738 | |
age 2461144023 | |
age 1270166272 | |
age 1025600095 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment