Created
January 2, 2013 00:04
-
-
Save gfredericks/4431141 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
(def all-bit-length-triples | |
(sort-by (fn [a] (vec (cons (apply max a) | |
(concat | |
(sort a) | |
a)))) | |
(for [a (range 9), b (range 9), c (range 9)] | |
[a b c]))) | |
(defn bindex | |
"Given a number in (range 256), returns the position of the rightmost | |
set bit, where 0 returns 0 and 1 returns 8." | |
[n] | |
(if (= 255 n) | |
0 | |
(loop [x 8, n n] | |
(if (or (zero? x) (odd? n)) | |
x | |
(recur (dec x) (/ n 2)))))) | |
(defn numbers-by-bindex | |
[n] | |
(filter (comp #{n} bindex) (range 256))) | |
(def all-colors | |
(for [[r g b] all-bit-length-triples, | |
r' (numbers-by-bindex r) | |
g' (numbers-by-bindex g) | |
b' (numbers-by-bindex b)] | |
[r' g' b'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment