Skip to content

Instantly share code, notes, and snippets.

@oliyh
Created March 17, 2014 16:49
Show Gist options
  • Save oliyh/9603200 to your computer and use it in GitHub Desktop.
Save oliyh/9603200 to your computer and use it in GitHub Desktop.
;; 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