Skip to content

Instantly share code, notes, and snippets.

@ndonolli
Last active June 26, 2019 14:52
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 ndonolli/2b2cea3a05929c558eb80aa33e0144ce to your computer and use it in GitHub Desktop.
Save ndonolli/2b2cea3a05929c558eb80aa33e0144ce to your computer and use it in GitHub Desktop.
; Write a function to determine if two words are anagrams.
(defn is-anagram [target src]
(if (string? target)
(if (= target src)
false
(is-anagram (frequencies target) src))
(= target (frequencies src))))
; Given a dictionary of words (such as this one), find all of the anagrams for a target word.
; Assumption: dictionary of words is a collection
(defn find-anagrams [target coll]
(let [target-freqs (frequencies target)]
(filter #(and (not= target %)(is-anagram target-freqs %)) coll)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment