I would be tempted to write a more recursive, slightly simpler solution to this problem. I have no idea if the following solution is more or less efficient than Lee&#39;s code, and also have not tested it.<br><br>(defn lib-test<br>

  [x y checked]<br>  (if (some #{[x y]} checked)<br>    checked<br>    (apply clojure.set/union<br>           (map #(lib-test (first %)<br>                           (second %)<br>                           (clojure.set/union checked #{[x y]}))<br>

                (friends x y)))))<br><br>This code is called on an x-y pair and an empty set, and returns a set of pairs. If the pair is in &#39;checked&#39;, then it just returns &#39;checked&#39;. Otherwise, it maps a function over the sequence returned by &#39;friends&#39;. The mapping function takes an x-y pair from &#39;friends&#39; and recursively calls lib-test on the pair as well as &#39;checked&#39; with [x y] added. The map results in a sequence of sets, where each set contains pairs that are in the group. Thus, we can just union them together to get the result.<br>

<br>Now that I think about it, this might find every path to every stone in a group. This may be of some concern, since it makes an algorithm that runs in O(n^2) time for a problem that should be solvable in linear time. Maybe to improve the efficiency, you need to do something like what Lee did. But, it&#39;s always helpful to see a different solution.<br>

<br>-Tom<br>