Last active
June 26, 2019 14:52
-
-
Save ndonolli/2b2cea3a05929c558eb80aa33e0144ce 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
; 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