Skip to content

Instantly share code, notes, and snippets.

@ivanbrennan
Created September 26, 2013 00:50
Show Gist options
  • Save ivanbrennan/6708355 to your computer and use it in GitHub Desktop.
Save ivanbrennan/6708355 to your computer and use it in GitHub Desktop.
Quiz submission
# 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)
minutes * 60
end
def minutes_in_hours(hours)
hours * 60
end
def hours_in_days(days)
days * 24
end
def days_in_weeks(weeks)
weeks * 7
end
def weeks_in_years(years)
years * 52
end
# Hours in a year. How many hours are in a year?
hrs_in_yr = hours_in_days(days_in_weeks(weeks_in_years(1)))
# Minutes in a decade. How many minutes are in a decade?
mins_in_dec = minutes_in_hours(hours_in_days(days_in_weeks(weeks_in_years(10))))
# Your age in seconds. How many seconds old are you?
age_in_sec = seconds_in_minutes(minutes_in_hours(hours_in_days(days_in_weeks(weeks_in_years(35)))))
# If I am 1,111 million seconds old, how old am I?
# Define an age_from_seconds method
def age_from_seconds(seconds)
age_mins = seconds / seconds_in_minutes(1)
age_hrs = age_mins / minutes_in_hours(1)
age_days = age_hrs / hours_in_days(1)
age_weeks = age_days / days_in_weeks(1)
age_years = age_weeks / weeks_in_years(1)
end
how_old_am_i = age_from_seconds(1111000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment