Created
April 15, 2016 23:22
-
-
Save larstvei/305a8ad1efea9d8fd961ea6a7262b726 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
(defn edge? [w1 w2] | |
(and (not= w1 w2) (= (last w1) (first w2)))) | |
(defn add-edges [m w words] | |
(let [edges (filter (partial edge? w) words)] | |
(assoc m w edges))) | |
(defn build-graph [words] | |
(reduce (fn [m w] (add-edges m w words)) {} words)) | |
(defn play [m w] | |
(if (empty? (m w)) | |
false | |
(not-every? (partial play (dissoc m w)) (filter m (m w))))) | |
(defn solve | |
([states] (filter (partial solve (build-graph states)) states)) | |
([m w] (every? (partial play (dissoc m w)) (m w)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment