Skip to content

Instantly share code, notes, and snippets.

@johnblanco
Created June 25, 2021 00:19
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 johnblanco/5fd38e7690a774141884f8d042f7369f to your computer and use it in GitHub Desktop.
Save johnblanco/5fd38e7690a774141884f8d042f7369f to your computer and use it in GitHub Desktop.
//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