Skip to content

Instantly share code, notes, and snippets.

@orend
Last active August 10, 2017 19:45
Show Gist options
  • Save orend/38e520dbadec13fe7d2f2947d29ccff6 to your computer and use it in GitHub Desktop.
Save orend/38e520dbadec13fe7d2f2947d29ccff6 to your computer and use it in GitHub Desktop.
(defn rotations [xs]
(take (count xs) (partition (count xs) 1 (cycle xs))))
(defn permutations [a-set]
(if (empty? a-set)
(list)
(mapcat
(fn [[x & xs]] (map #(cons x %) (permutations xs)))
(rotations a-set))))
;; based on https://codereview.stackexchange.com/questions/135737/generate-all-permutations-in-clojure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment