Last active
August 10, 2017 19:45
-
-
Save orend/38e520dbadec13fe7d2f2947d29ccff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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