Skip to content

Instantly share code, notes, and snippets.

@jawher
Created July 9, 2010 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawher/468846 to your computer and use it in GitHub Desktop.
Save jawher/468846 to your computer and use it in GitHub Desktop.
(defn permutations "P26" [n xs]
(if (= 1 n)
(map list xs)
(reduce #(let [s (split-at (inc %2) xs)
ps (permutations (dec n) (last s))
a (last (first s))]
(concat %1 (map (fn [p] (cons a p)) ps )))
'() (range 0 (inc (- (count xs) n))))
))
(permutations 6 '(\a \b \c \d \e \f \g \h))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment