-
-
Save putraxor/655c673bf48400407220c4d384aec0e6 to your computer and use it in GitHub Desktop.
Given some amount, return possible values that constructed by particular denomination
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
val denom = arrayOf(1, 2, 5, 10, 20, 50, 100) | |
val amount = arrayOf(5, 11, 53, 122, 155, 157, 210, 200) | |
fun main(args: Array<String>) = amount.forEach { currentAmount -> | |
val suggestions = mutableListOf<Int>() | |
denom.forEach { | |
if (it >= currentAmount) { | |
suggestions += it | |
} else { | |
val anotherFactor = Math.ceil(currentAmount.toDouble() / it) | |
suggestions += it * anotherFactor.toInt() | |
} | |
} | |
println("$currentAmount : ${suggestions.distinct()}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment