Created
March 17, 2014 16:49
-
-
Save oliyh/9603200 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
;; binary-like count with n 'bits' which can have values between from and to | |
;; e.g. (permutations 3 0 3) -> ([0 0] [0 1] [0 2] [1 0] [1 1] [1 2] [2 0] [2 1] [2 2]) | |
(defn permutations [n from to] | |
(let [symbols (into [] (take n (repeatedly gensym))) | |
ranges (take n (repeatedly #(into [] (range from to)))) | |
bindings (into [] (interleave symbols ranges))] | |
(eval `(for ~bindings ~symbols)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment