Created
July 19, 2015 12:30
-
-
Save DeathRay1977/e312c5c9f51691e3ad88 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
(ns anagram | |
(:require [clojure.string :refer [lower-case upper-case]])) | |
(defn- canonicalize | |
[word] | |
(-> word | |
lower-case | |
frequencies)) | |
(defn- uppercase? | |
"Tests to see if the string given as the first argument is the uppercase version of the second " | |
[s w] | |
(= s (upper-case w))) | |
(defn anagrams-for | |
[word candidates] | |
(let [canonical (canonicalize word)] | |
(vec (filter #(and (not (uppercase? word %)) (not= word %) (= canonical (canonicalize %))) candidates)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment