Last active
December 23, 2015 23:19
-
-
Save gregeng/6709402 to your computer and use it in GitHub Desktop.
quiz
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
# 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(time = 1) | |
time * 60 | |
end | |
def minutes_in_hours(time = 1) | |
time * 60 | |
end | |
def hours_in_days(time = 1) | |
time * 24 | |
end | |
def days_in_weeks(time = 1) | |
time * 7 | |
end | |
def weeks_in_years(time = 1) | |
time * 52 | |
end | |
def years_to_hours(time = 1) | |
weeks_in_years( | |
days_in_weeks( | |
hours_in_days(time) | |
) | |
) | |
end | |
def years_to_minutes(time = 1) | |
weeks_in_years( | |
days_in_weeks( | |
hours_in_days( | |
minutes_in_hours() | |
) | |
) | |
) | |
end | |
def years_to_seconds(time = 24) | |
weeks_in_years( | |
days_in_weeks( | |
hours_in_days( | |
minutes_in_hours( | |
seconds_in_minutes(time) | |
) | |
) | |
) | |
) | |
end | |
def age_from_seconds(time = 1111111111) | |
time / 60 / 60 / 24 / 365 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment