No title Revision 323637636337 (Sun Aug 26 2012 at 08:07) - Diff Link to this snippet: https://friendpaste.com/7QiF9pQ1oe3J5KgTEKwDII Embed: manni perldoc borland colorful default murphy trac fruity autumn bw emacs pastie friendly Show line numbers Wrap lines 123456789101112131415( (fn tour? ([g] (some boolean (map (partial tour? g) (set (flatten g))))) ; try each node as starting point ([g r] ; is the graph visitable from the "r" root node? (let [connected? (fn [n [x y]] (cond (= n x) y (= n y) y)) ; return the connected node, if any connected (keep-indexed ; return the nodes connected to the root, and their index #(let [conn (connected? r %2)] (if conn [conn %1])) g) candidates (map (fn [[n i]] [(concat (take (dec i) g) (drop i g)) n]) connected)] ; candidates are "new" root nodes, and the remaining graphs (or (empty? g) (and (not (empty? connected)) (some boolean (map #(apply tour? %) candidates)))))))[[:a :b] [:a :c] [:c :b] [:a :e] [:b :e] [:a :d] [:b :d] [:c :e] [:d :e] [:c :f] [:d :f]])