Skip to content

Instantly share code, notes, and snippets.

@stevenabrooks
Created June 7, 2013 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenabrooks/5726485 to your computer and use it in GitHub Desktop.
Save stevenabrooks/5726485 to your computer and use it in GitHub Desktop.
# quiz.rb
# Write a program that tells you the following:
#
# Hours in a year. How many hours are in a year? - 6pts
# Minutes in a decade. How many minutes are in a decade? - 6pts
# Your age in seconds. How many seconds old are you? - 6pts
#
# Define at least the following methods to accomplish these tasks:
#
# seconds_in_minutes(1) #=> 60 - 3pts
# minutes_in_hours(1) #=> 60 - 3pts
# hours_in_days(1) #=> 24 - 3pts
# days_in_weeks(1) #=> 7 - 3pts
# weeks_in_years(1) #=> 52 - 3pts
#
# If I am 1,111 million seconds old, how old am I?
# Define an age_from_seconds method - 7pts
seconds_in_minutes = 60
minutes_in_hours = 60
hours_in_days = 24
days_in_weeks = 7
weeks_in_years = 52
# Question 1: hours in a year.
hours_in_year = weeks_in_years * days_in_weeks * hours_in_days
# Question 2: minutes in a decade.
minutes_in_decade = (minutes_in_hours * hours_in_days * days_in_weeks * weeks_in_years) * 10
# Question 3: age in seconds.
def age_in_seconds(age)
seconds_in_minutes = 60
minutes_in_hours = 60
hours_in_days = 24
days_in_weeks = 7
weeks_in_years = 52
seconds_in_minutes * minutes_in_hours * hours_in_days * days_in_weeks * weeks_in_years * age
end
puts age_in_seconds(25)
# Question 4: if I'm 1,111 million seconds old, how old am I?
def age_from_seconds(seconds)
seconds_in_minutes = 60
minutes_in_hours = 60
hours_in_days = 24
days_in_weeks = 7
weeks_in_years = 52
seconds / (seconds_in_minutes * minutes_in_hours * hours_in_days * days_in_weeks * weeks_in_years)
end
puts age_from_seconds(1111e6)
# For some reason if we did not have all the variables available inside it would not locate them elsewhere. Probably not best practice but worked.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment