Last active
December 11, 2015 23:28
-
-
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.
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
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