Skip to content

Instantly share code, notes, and snippets.

@cacaocake
Last active May 23, 2019 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cacaocake/9338fd4eeb02b1c89c2b7334e9f2206b to your computer and use it in GitHub Desktop.
Save cacaocake/9338fd4eeb02b1c89c2b7334e9f2206b to your computer and use it in GitHub Desktop.
Penguin Problem
function letsEat(amount, bonus) {
var total = 0
var currentLeft = amount
while(currentLeft >= bonus) {
var thisTrunBonus = Math.floor(currentLeft / bonus)
var thisTurnEat = thisTrunBonus * bonus
total += thisTurnEat
currentLeft = currentLeft - thisTurnEat + thisTrunBonus
}
return total + currentLeft
}
console.log(letsEat(20,3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment