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
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) | |
} |
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
(def ^{:dynamic true} *print-progress* true) | |
(defmacro with-progress | |
"Bind a `reportfn` function, and evaluate `body` wherein | |
calling (report!) will invoke the report function with the current | |
state of the iteration." | |
[reportfn & body] | |
`(let [iter# (atom 0) | |
reporter# ~reportfn] | |
(letfn [(~'report! [] |