Created
November 30, 2009 17:37
-
-
Save mdemare/245588 to your computer and use it in GitHub Desktop.
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
(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