Created
September 3, 2012 21:23
-
-
Save l1x/3613696 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
(:use [clojure.string :only [lower-case split-lines replace-first]])) | |
(def dictionary | |
(into #{} | |
(map lower-case | |
(split-lines (slurp "/usr/share/dict/words"))))) | |
(def alphabet "abcdefghijklmnopqrstuvwxyz") | |
(defn neighbor-words [^String word] | |
"Return a lazy-seq with words which differ from | |
the input word by only the first letter" | |
(remove #{word} (into [] | |
(filter dictionary | |
(let [[f & r] word] | |
(for [abc alphabet] | |
(replace-first word f (str abc)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment