• (lex-permutations c)
Fast lexicographic permutation generator for a sequence of numbers

1 Example top

  • Clojure=> (lex-permutations [1 2 3])
    ([1 2 3] [1 3 2] [2 1 3] [2 3 1] [3 1 2] [3 2 1])
    Clojure=> (lex-permutations [1 1 2])
    ([1 1 2] [1 2 1] [2 1 1])
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/contrib/combinatorics.clj:151 top

(defn lex-permutations
  "Fast lexicographic permutation generator for a sequence of numbers"
  [c]
  (lazy-seq
   (let [vec-sorted (vec (sort c))]
     (if (zero? (count vec-sorted))
       (list [])
       (vec-lex-permutations vec-sorted)))))
Vars in clojure.contrib.combinatorics/lex-permutations: count defn lazy-seq let list zero?
Used in 0 other vars

Comments top

No comments for lex-permutations. Log in to add a comment.