Skip to content

Instantly share code, notes, and snippets.

@rayning0
Created September 26, 2013 03:40
Show Gist options
  • Save rayning0/6709617 to your computer and use it in GitHub Desktop.
Save rayning0/6709617 to your computer and use it in GitHub Desktop.
Quiz - Seconds to Years
# 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(t)
t * 60.0
end
def minutes_in_hours(t)
t * 60.0
end
def hours_in_days(t)
t * 24.0
end
def days_in_weeks(t)
t * 7.0
end
def weeks_in_years(t)
t * 52.0
end
def age_from_seconds(t)
t / (weeks_in_years(1) * days_in_weeks(1) * hours_in_days(1) * minutes_in_hours(1) * seconds_in_minutes(1))
end
hoursyear = weeks_in_years(1) * days_in_weeks(1) * hours_in_days(1)
mindecade = weeks_in_years(10) * days_in_weeks(1) * hours_in_days(1) * minutes_in_hours(1)
secsold = weeks_in_years(35) * days_in_weeks(1) * hours_in_days(1) * minutes_in_hours(1) * seconds_in_minutes(1)
puts "There are #{hoursyear} hours in 1 year."
puts "There are #{mindecade} min in 1 decade."
puts "I'm #{secsold} seconds old."
puts "I'm #{age_from_seconds(1111e6)} years old."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment