Skip to content

Instantly share code, notes, and snippets.

@mepcotterell
Created February 2, 2012 19:09
Show Gist options
  • Save mepcotterell/1725164 to your computer and use it in GitHub Desktop.
Save mepcotterell/1725164 to your computer and use it in GitHub Desktop.
Combination Examples
object Combo extends App {
val vars = List("a", "b", "c", "d")
val list = vars map (e => ("-%s".format(e), "+%s".format(e)))
val len = list.size
val combos = math.pow(2, len).toInt
for (i <- 0 until combos) {
for (j <- 0 until len) {
val (off, on) = list(j)
print ("%s ".format(if ((i >> j) % 2 == 0) off else on))
} // for
println
} // for
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment