Skip to content

Instantly share code, notes, and snippets.

@TylerLH
Last active August 29, 2015 13:59
Show Gist options
  • Save TylerLH/2ed3bbb789690efda32e to your computer and use it in GitHub Desktop.
Save TylerLH/2ed3bbb789690efda32e to your computer and use it in GitHub Desktop.
R = 2.0 # Cookies per second
C = 500.0 # Cost of a farm
F = 4.0 # CPS per farm owned
X = 2000.0 # Cookies needed to win
elapsedTime = 0.0
cookies = 0.0
timeForNextFarm = ->
cookiesNeeded = C - cookies
time = cookiesNeeded/R
return time
timeUntilWin = ->
return (X-cookies)/R
timeToWinIfFarmIsPurchased = ->
new_cookies = cookies-C
rate = R + F
time = (X-new_cookies)/rate
return time
purchaseFarm = ->
return if cookies < C
elapsedTime = timeForNextFarm() + elapsedTime
R = R + F
cookies = cookies - C
tick = ->
elapsedTime++
cookies = cookies + R
if cookies >= X
return console.log "Won in #{elapsedTime} seconds"
if timeToWinIfFarmIsPurchased() < timeUntilWin()
purchaseFarm()
process.nextTick tick
tick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment