Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Given some amount, return possible values that constructed by particular denomination
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()}")
}
@esafirm

This comment has been minimized.

Copy link
Owner Author

@esafirm esafirm commented Jul 28, 2017

5 : [5, 6, 10, 20, 50, 100]
11 : [11, 12, 15, 20, 50, 100]
53 : [53, 54, 55, 60, 100]
122 : [122, 125, 130, 140, 150, 200]
155 : [155, 156, 160, 200]
157 : [157, 158, 160, 200]
210 : [210, 220, 250, 300]
200 : [200]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.