Created
June 18, 2012 22:06
-
-
Save maruks/2951012 to your computer and use it in GitHub Desktop.
my code from code dojo 8
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 code-dojo.core | |
(:use [code-dojo.core] [clojure.math.combinatorics] [clojure.java.io :only (reader)]) | |
(:use [speclj.core])) | |
(def dictionary | |
(map #(.toLowerCase %) | |
(line-seq (reader "english_words.txt")))) | |
(defn same-length [len coll] | |
(filter #(= len (count %)) coll)) | |
(defn anagrams [string] | |
(let [perms (map #(apply str %) (permutations string)) | |
strings (same-length (count string) dictionary)] | |
(filter #(some #{%} strings) perms))) | |
(describe "anagram test" | |
(it "tea has anagram eat" | |
(should (some #{"eat"} (anagrams "tea") ))) | |
(it "tea doesnt have anagram tae" | |
(should-not (some #{"tae"} (anagrams "tea") ))) | |
(it "zoo has anagram zoo" | |
(should (some #{"zoo"} (anagrams "zoo") ))) | |
(it "all anagrams have the same lenght" | |
(should (every? #(= 3 (.length %)) (anagrams "zoo")))) | |
(it "headache doesnt have anagram ache" | |
(should-not (some #{"headache"} (anagrams "ache") )))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment