On 12/4/05, Levin Alexander <levin / grundeis.net> wrote: > > Yes, this is quite nice. I rewrote it a bit so that it does not need > the nested ifs. What do you think? > > def sum_in_subset?(div = self.divisors) > return false if self < 0 > return false if div.empty? > return true if div.include?(self) > > f, remaining = div[0], div[1..-1] > (self - f).sum_in_subset?(remaining) or sum_in_subset?(remaining) > end I don't really like multiple returns, which is why I wrote it like that. But the above is still pretty nice, and certainly more succinct. Here you can also see how similar this is to Rob Leslie's method of finding the sums of the subsets. He posted before me though and deserves credit as well for a nice and fast solution. His solution is in the original quiz thread. Ryan