Skip to content

Instantly share code, notes, and snippets.

@jadon1979
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save jadon1979/99f062943c35ccbf86fe to your computer and use it in GitHub Desktop.

Select an option

Save jadon1979/99f062943c35ccbf86fe to your computer and use it in GitHub Desktop.
Spin Off of Google code jam Cookie clicker.
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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment