Skip to content

Instantly share code, notes, and snippets.

@elfenlaid
Created October 1, 2013 17:31
Show Gist options
  • Save elfenlaid/6782152 to your computer and use it in GitHub Desktop.
Save elfenlaid/6782152 to your computer and use it in GitHub Desktop.
(defn one-or-no-letter-diff? [a b]
(loop [xs (seq a)
ys (seq b)]
(cond
(= xs ys) true
(and (empty? xs) (= (count ys) 1)) true
(and (empty? ys) (= (count xs) 1)) true
(= (first xs) (first ys)) (recur (rest xs) (rest ys))
:else (or (= (rest xs) ys) (= (rest ys) xs) (= (rest xs) (rest ys))))))
(defn path-exists? [coll word]
(if (empty? coll) true
(let [mutable-words (filter (partial one-or-no-letter-diff? word) coll)]
(some #(path-exists? (disj coll %) %) mutable-words))))
(defn word-chain? [coll]
(if (some #(path-exists? (disj coll %) %) coll) true false))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment