Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created October 11, 2017 18:13
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 cemerick/44b62ef2b2e7b7bf6015cf5456cc476e to your computer and use it in GitHub Desktop.
Save cemerick/44b62ef2b2e7b7bf6015cf5456cc476e to your computer and use it in GitHub Desktop.
(def words (set (.split (slurp "g:/words") "\n")))
=> #'user/words
(count words)
=> 99171
(require '[clojure.math.combinatorics :refer (permutations)])
=> nil
(count (permutations "plates"))
=> 720
(first (permutations "plates"))
=> (\p \l \a \t \e \s)
(defn anagrams-of [s]
(->> (permutations s)
(map #(apply str %))
(filter words)))
=> #'user/anagrams-of
(anagrams-of "plates")
=> ("plates" "pleats" "palest" "pastel" "petals" "staple")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment