Created
April 8, 2009 03:10
-
-
Save chendo/91607 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://mozy.com/contest | |
# Question 4 | |
# chendo's solution | |
require 'benchmark' | |
year = 0 | |
fibs = [2, 0, 0, 0, 0] # age 0, 1, 2, 3, 4 | |
adults = 0 # age > 5 | |
Benchmark.bm do |bm| | |
bm.report do | |
while year < 75000 | |
year += 1 | |
fibs.unshift(adults += fibs.pop) | |
end | |
puts "At #{year} years, there would be #{adults + fibs.inject(0) { |mem, i| mem += i }}" | |
end | |
end | |
# user system total real | |
# At 75 years, there would be 1457183502 | |
# 0.000000 0.000000 0.000000 ( 0.000675) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment