Skip to content

Instantly share code, notes, and snippets.

@keithharper
Last active July 1, 2019 10:43
Show Gist options
  • Save keithharper/74cb6cb0fa60d0ebe31949e67a0d9751 to your computer and use it in GitHub Desktop.
Save keithharper/74cb6cb0fa60d0ebe31949e67a0d9751 to your computer and use it in GitHub Desktop.
Harder Anagrams
(defn anagrams? [words1 words2]
  (let [xf (comp sort
                 (partial re-seq #"[^\s]")
                 clojure.string/lower-case
                 str)]
    (= (xf words1)
       (xf words2))))

Examples:

(filter (partial anagrams? "real fun") 
        dictionary)
=> ("funeral")

(filter (partial anagrams? "stand under")
        dictionary)
=> ("understand")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment