Last active
January 20, 2018 17:21
-
-
Save FlorianCassayre/e5f1b64baf7c7defb2fc6e3eb5b02d53 to your computer and use it in GitHub Desktop.
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
object CompteBonCombinations extends App { | |
val plates = { | |
val small = (1 to 10).toList | |
val big = List(25, 50, 75, 100) | |
small ++ small ++ big | |
} | |
val grouped = plates.groupBy(identity).mapValues(_.size) | |
def combinations(map: Map[Int, Int], n: Int): Int = { | |
if (n == 0) | |
1 | |
else if (map.isEmpty) | |
0 | |
else { | |
val (k, v) = map.head | |
val updated = if (v == 1) map - k else map + (k -> (v - 1)) | |
combinations(updated, n - 1) + combinations(map.tail, n) | |
} | |
} | |
println(combinations(grouped, 5) * (100 to 999).size) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment