Created
October 1, 2013 17:31
-
-
Save elfenlaid/6782152 to your computer and use it in GitHub Desktop.
solution for http://www.4clojure.com/problem/82#prob-title task
This file contains hidden or 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
(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