From: Benoit Daloze Date: 2009-11-24T08:08:14+09:00 Subject: Re: Distinct Sets (#225) --0016e659f4663e80a8047911e659 Content-Type: text/plain; charset=ISO-8859-1 I must admit is a very elegant solution. And it's not so slow, 0.36s with my tests and adding .map { |s| s.flatten.to_a*.sort* }, it pass all the tests without sorting. Awesome for a Ruby-based class! A nice exemple of using forgot methods like divide. 2009/11/23 > Here's my not-fast solution: > > require 'set' > > class Set > def intersect?(other) > other.each { |o| return true if include?(o) } > false > end > end > > def distinct_sets(array_of_arrays) > set_of_sets = array_of_arrays.map{|a| > a.to_set > }.to_set > > set_of_sets.divide{|i, j| > i.intersect?(j) > }.map{|s| > s.flatten.to_a > } > end > > Adding the intersect? method to Set was primarily motivated by > readability, but also provided a noticeable speed improvement over my > original alternative (intersection.size.>). > > --0016e659f4663e80a8047911e659--