Skip to content

Instantly share code, notes, and snippets.

@l1x
Created September 3, 2012 21:23
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 l1x/3613696 to your computer and use it in GitHub Desktop.
Save l1x/3613696 to your computer and use it in GitHub Desktop.
(: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