Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I'm not good at math so I'm pretty sure I did the calculations wrong
- # hours in a year -----------------------------------------------------
- def hoursInYear
- 24*365
- end
- # If I am 1031 million seconds old, how old am I? ---------------------
- def secondsInYears(age_in_seconds)
- age_in_seconds / (60 * 60 *24 * 365 )
- end
- # minutes in a decade
- def minsInDecade
- 60*24*7*4*12
- end
- # how many seconds are you --------------------------------------------
- def ageInSeconds(age)
- 60*60*24*7*4*12*age
- # Not accounting for partial years
- end
- # chocolates will you eat in your life ---------------------------------
- def chocolatesInLifetime(amount)
- # assume they'll live to 90?
- # there are 52 weeks in a year
- # assume the estimate includes past eaten chocolates
- 52 * 90 * amount
- # Doesn't account for 0 chocolates per week, since I don't know
- # how many they've eaten in the past
- end
- # ask first middle last names ------------------------------------------
- def greeting(first, middle, last)
- puts "Hello #{first} #{middle} #{last}."
- end
- # Table of contents ---------------------------------------------------
- book = "Think Like a Programmer: An Introducion to Creative Problem Solving"
- author = "V. Anton Spraul"
- # The website doesn't list the pages so I just made them up.
- # toc = table of contents
- toc = {"Strategies for Problem Solving"=> 1, "Pure Puzzles"=> 2, "Problems with Arrays"=> 3, "Solving Problems with Pointers and Dynamic Memory"=> 4, "Solving Problems with Classes"=> 5, "Solving Problems with Recursion"=> 6, "Solving Problems with Code Reuse"=> 7, "Thinking Like a Programmer"=> 8}
- # Now let's do some stuff!
- puts "There are #{hoursInYear} hours in a year."
- puts "And #{secondsInYears(1031000000)} years in 1031 million seconds!"
- puts "There are #{minsInDecade} minutes in a decade."
- puts "Hello, what's your name?"
- puts "First name:"
- first_name = gets.chomp
- puts "Middle name:"
- middle_name = gets.chomp
- puts "Last name:"
- last_name = gets.chomp
- puts "Greetings, #{first_name} #{middle_name} #{last_name}!"
- puts "How old are you?"
- age = gets.chomp
- puts "You are #{ageInSeconds age.to_i} seconds old!"
- puts "How many chocolates do you eat per week?"
- amount = gets.chomp
- puts "You'll eat about #{chocolatesInLifetime amount.to_i} chocolates in your lifetime!"
- puts "What's your favorite number, #{first_name}?"
- num = gets.chomp
- puts "But #{num.to_i + 1} is so much better!"
- puts "WHAT DO YOU WANT, #{first_name}?!"
- want = gets.chomp
- puts "WHADDAYA MEAN YOU WANT #{want.upcase}?!?!?! GET OUTTA HERE!"
- puts "Hey #{first_name}, here's a cool book I'm reading:"
- puts "#{book} by #{author}"
- # None of the tutorials I read covered ljust/rjust usage
- # Compiler gives "undefined method `rjust'" error
- # So I'm just going to use tabs ( /t )
- puts "Here's the chapters:"
- toc.each do | chapter, page|
- puts "Page #{page} \t #{chapter}"
- end
Advertisement
Add Comment
Please, Sign In to add comment