Skip to content

Instantly share code, notes, and snippets.

@DeathRay1977
Created July 19, 2015 12:30
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 DeathRay1977/e312c5c9f51691e3ad88 to your computer and use it in GitHub Desktop.
Save DeathRay1977/e312c5c9f51691e3ad88 to your computer and use it in GitHub Desktop.
(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