Last active
July 30, 2017 03:35
-
-
Save esafirm/f77529919e426024d9ac1e53c6819f13 to your computer and use it in GitHub Desktop.
Given some amount, return possible values that constructed by particular denomination
This file contains hidden or 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()}") | |
} |
Author
esafirm
commented
Jul 28, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment