Skip to content

Instantly share code, notes, and snippets.

@irmiller22
Created September 26, 2013 02:57
Show Gist options
  • Save irmiller22/6709299 to your computer and use it in GitHub Desktop.
Save irmiller22/6709299 to your computer and use it in GitHub Desktop.
quiz
# 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
hours_in_year = 365 * 24
minutes_in_decade = hours_in_year * 10 * 60
age_in_seconds = 25 * hours_in_year * 60
def seconds_in_minutes(minutes)
minutes*60
end
def minutes_in_hours(hours)
hours*60
end
def seconds_in_hours(hours)
seconds_in_minutes(minutes_in_hours(hours))
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
def age_from_seconds(seconds)
seconds/(60*60*24*365)
end
age_from_seconds(1111000000)
seconds_in_hours(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment