Anagrams: Difference between revisions

Content deleted Content added
Added Oz.
added Clojure version
Line 314:
elan, lane, lean, lena, neal,
evil, levi, live, veil, vile,
 
=={{header|Clojure}}==
Assume ''wordfile'' is the path of the local file containing the words. This code makes a map (''groups'') whose keys are sorted letters and values are lists of the key's anagrams. It then determines the length of the longest list, and prints out all the lists of that length.
<lang lisp>
(import '(java.io FileReader BufferedReader))
 
(def words (-> wordfile FileReader. BufferedReader. line-seq))
 
(let [f (fn [tbl word] (update-in tbl [(sort word)] conj word))]
(def groups (reduce f {} words))
 
(let [wordlists (vals groups)
longest (apply max (map count wordlists))]
(doseq [wordlist wordlists :when (= (count wordlist) longest)]
(println wordlist)))
</lang>
 
=={{header|Common Lisp}}==