( (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]])