Created
June 25, 2021 00:19
-
-
Save johnblanco/5fd38e7690a774141884f8d042f7369f to your computer and use it in GitHub Desktop.
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
//https://old.reddit.com/r/dailyprogrammer/comments/nucsik/20210607_challenge_393_easy_making_change/ | |
class MakingChange { | |
fun change(amount: Int): Int { | |
var currentAmount = amount | |
var coinCount = 0 | |
val possibleCoins = listOf(1, 5, 10, 25, 100, 500).sorted().reversed() | |
for (coin in possibleCoins) { | |
while (coin <= currentAmount) { | |
coinCount++ | |
currentAmount -= coin | |
} | |
} | |
return coinCount | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment