Created
September 26, 2013 12:34
-
-
Save rosiehoyem/6713534 to your computer and use it in GitHub Desktop.
Exercise from Sept 25.
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
# Write a program that tells you the following: | |
# | |
# Hours in a year. How many hours are in a year? | |
# Minutes in a decade. How many minutes are in a decade? | |
# Your age in seconds. How many seconds old are you? | |
# | |
# Define at least the following methods to accomplish these tasks: | |
# | |
# seconds_in_minutes(1) | |
# minutes_in_hours(1) | |
# hours_in_days(1) | |
# days_in_weeks(1) | |
# weeks_in_years(1) | |
# | |
# If I am 1,111 million seconds old, how old am I? | |
# Define an age_from_seconds method | |
def seconds_in_minutes(minutes) | |
60 * minutes | |
end | |
def minutes_in_hours(hours) | |
60 * hours | |
end | |
def hours_in_days(hours) | |
24 * hours | |
end | |
def days_in_weeks(days) | |
7 * days | |
end | |
def weeks_in_years(weeks) | |
52 * weeks | |
end | |
def age_from_seconds(seconds) | |
seconds / (60.0 * 60 * 24 * 7 * 52) | |
end | |
age = age_from_seconds(1111111111) | |
puts "Somebody is #{age} years old." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment