Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created August 14, 2012 04:09
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 amalloy/3346186 to your computer and use it in GitHub Desktop.
Save amalloy/3346186 to your computer and use it in GitHub Desktop.
(letfn [(remove-once [x coll]
(lazy-seq
(let [y (first coll)]
(if (= x y)
(rest coll)
(cons y (remove-once x (rest coll)))))))]
(defn permute [coll]
(lazy-seq
(if-let [coll (seq coll)]
(for [x coll,
perm (permute (remove-once x coll))]
(cons x perm))
'(())))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment