Skip to content

Instantly share code, notes, and snippets.

View mtm's full-sized avatar

Mike T. Miller mtm

  • Sarasota, FL
View GitHub Profile
@dcbriccetti
dcbriccetti / gist:b70a7ff65541d79c467d
Last active August 29, 2015 14:16
Can you rewrite this to produce “combinations” for any nonzero value of “numDice”? (This is mostly academic curiosity.)
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)
}
@mtm
mtm / progress.clj
Created May 11, 2012 18:08 — forked from kriyative/progress.clj
First cut implementation of `with-progress` and `report!`
(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! []