Clojure=> (permutations [1 2 3]) ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)) Clojure=> (permutations [1 1 2]) ((1 1 2) (1 2 1) (1 1 2) (1 2 1) (2 1 1) (2 1 1))
(defn permutations
"All the permutations of items, lexicographic by index"
[items]
(let [v (vec items)]
(map #(map v %) (lex-permutations (range (count v))))))
Comments top
No comments for permutations. Log in to add a comment.