Skip to content

Instantly share code, notes, and snippets.

@mdemare
Created November 30, 2009 17:37
Show Gist options
  • Save mdemare/245588 to your computer and use it in GitHub Desktop.
Save mdemare/245588 to your computer and use it in GitHub Desktop.
(defn multibool [& args]
(let [offset ({6 2, 11 3, 20 4} (count args))]
(if-not offset
(throw
(IllegalArgumentException.
"Illegal number of arguments (expected: 2 + 4, 3 + 8, 4 + 16)")))
(nth args
(+ offset
(reduce (fn [sum i] (+ sum (if (nth args i)
(bit-shift-left 1 (- (dec offset) i))
0)))
0
(range offset))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment