Skip to content

Instantly share code, notes, and snippets.

@gzoritchak
Last active December 11, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gzoritchak/4676653 to your computer and use it in GitHub Desktop.
Save gzoritchak/4676653 to your computer and use it in GitHub Desktop.
Une solution non optimisée mais j'ai fait le choix de la lisibilité sachant que la valeur max recherchée était de 100.
import codestory2013.gzoritchak.scalaskel.Coin.*
import java.util.*
enum class Coin(val value: Int) {
foo : Coin(1)
bar : Coin(7)
qix : Coin(11)
baz : Coin(21)
}
//Pas optimisé du tout mais fait le job avec simplicité max.
fun change(value: Int): Set<Map<Coin, Int>> {
val ret = hashSetOf<Map<Coin, Int>>()
for (fooCount in 0..value)
for (barCount in 0..(value/bar.value))
for (qixCount in 0..(value/qix.value))
for (bazCount in 0..(value/baz.value))
if( fooCount * foo.value +
barCount * bar.value +
qixCount * qix.value +
bazCount * baz.value == value)
ret.add(hashMapOf(
foo to fooCount,
bar to barCount,
qix to qixCount,
baz to bazCount))
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment