Last active
August 29, 2015 14:16
-
-
Save dcbriccetti/b70a7ff65541d79c467d to your computer and use it in GitHub Desktop.
Can you rewrite this to produce “combinations” for any nonzero value of “numDice”? (This is mostly academic curiosity.)
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 combinations: Seq[Seq[Int]] = numDice match { | |
case 1 => for (a <- 1 to numSides) yield Seq(a) | |
case 2 => for (a <- 1 to numSides; b <- 1 to numSides) yield Seq(a, b) | |
case 3 => for (a <- 1 to numSides; b <- 1 to numSides; c <- 1 to numSides) yield Seq(a, b, c) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't help with Scala (been away too long), but here's a way to do it in Clojure: