This example was given as a spin-off to the Google Code Jam “Cookie Clicker” challenge.
class Investor
def initialize(*args)
@c, @f, @x = args
@income = 2.0
@seconds = 0
end
def solve
return proper_seconds if (@x-@c)/@income < @x/(@income + @f)
@seconds += @c/@income
@income += @f
solve
end
def proper_seconds
(@seconds + @x/@income).round(7)
end
end
values = [
[30.0, 1.0, 2.0],
[30.0, 2.0, 100.0],
[30.5, 3.14159,1999.1999],
[500.0, 4.0, 2000.0]
]
values.each { |settings| puts Investor.new(*settings).solve }
You must log in to post a comment.