Skip to content

Instantly share code, notes, and snippets.

@leira
Created August 18, 2017 10:04
Show Gist options
  • Save leira/0e3db4155e03d385c2615f163a85c2ef to your computer and use it in GitHub Desktop.
Save leira/0e3db4155e03d385c2615f163a85c2ef to your computer and use it in GitHub Desktop.
Generate all the len length sequences with elements from xs #clojure
(defn selections [xs len]
(if (zero? len)
[[]]
(mapcat (fn [pd] (map #(conj pd %) xs))
(selections xs (dec len)))))
(defn selections-with-all [xs len]
(filter #(= (set %) (set xs)) (permu xs len)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment