Skip to content

Instantly share code, notes, and snippets.

@FlorianCassayre
Last active January 20, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FlorianCassayre/e5f1b64baf7c7defb2fc6e3eb5b02d53 to your computer and use it in GitHub Desktop.
Save FlorianCassayre/e5f1b64baf7c7defb2fc6e3eb5b02d53 to your computer and use it in GitHub Desktop.
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