| a | b | |
|---|
| 0 | + | ( |
|---|
| 0 | + | (fn tour? |
|---|
| 0 | + | ([g] (some boolean (map (partial tour? g) (set (flatten g))))) ; try each node as starting point |
|---|
| 0 | + | ([g r] ; is the graph visitable from the "r" root node? |
|---|
| 0 | + | (let [connected? (fn [n [x y]] (cond (= n x) y (= n y) y)) ; return the connected node, if any |
|---|
| 0 | + | connected (keep-indexed ; return the nodes connected to the root, and their index |
|---|
| 0 | + | #(let [conn (connected? r %2)] |
|---|
| 0 | + | (if conn [conn %1])) g) |
|---|
| 0 | + | candidates (map (fn [[n i]] [(concat (take (dec i) g) (drop i g)) n]) connected)] |
|---|
| 0 | + | (or (empty? g) |
|---|
| 0 | + | (and (not (empty? connected)) |
|---|
| 0 | + | (some boolean (map #(apply tour? %) candidates))))))) |
|---|
| 0 | + | [[:a :b] [:a :c] [:c :b] [:a :e] |
|---|
| 0 | + | [:b :e] [:a :d] [:b :d] [:c :e] |
|---|
| 0 | + | [:d :e] [:c :f] [:d :f]]) |
|---|
| ... | |
|---|