Last active
May 23, 2019 21:32
-
-
Save cacaocake/9338fd4eeb02b1c89c2b7334e9f2206b to your computer and use it in GitHub Desktop.
Penguin Problem
This file contains 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
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