From: Rob Biedenharn Date: 2009-11-22T15:02:57+09:00 Subject: Re: [QUIZ] Distinct Sets (#225) On Nov 21, 2009, at 11:50 AM, brabuhr@gmail.com wrote: > On Fri, Nov 20, 2009 at 9:23 PM, Daniel Moore > wrote: >> >> ## Distinct Sets (#225) >> >> Aloha Rubyists, >> >> This week's quiz comes from Ruby Quiz Suggestions MVP Martin >> DeMello[1]. >> >> [based on a surprisingly tricky stackoverflow problem] >> >> You have an list of sets, which you want to transform by the >> following >> method: if any two sets have a common element, merge them into a >> single set. You will be left with a reduced list partitioning all the >> elements into sets where every set is disjoint from every other. > > $ ruby -v 225.rb > ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0] > Loaded suite 225 > Started > . > Finished in 0.059557 seconds. > > 1 tests, 10 assertions, 0 failures, 0 errors > > But, I cheated a bit in my assertions; sorting the expected and actual > values before asserting them equal: I'm sure that there's a better way than mine, but it seems to work well. ruby -v -rubygems distinct_sets_test.rb ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] /Library/Ruby/Gems/1.8/gems/thoughtbot-shoulda-2.9.1/lib/shoulda/ context.rb:4: warning: method redefined; discarding old contexts Loaded suite distinct_sets_test Started .................... Finished in 0.018326 seconds. 20 tests, 148 assertions, 0 failures, 0 errors This includes all the tests given in the original quiz description and all the tests from brabuhr@gmail.com, but using Shoulda and splitting the one "tests" method with 10 assertions into 4 separate methods with one assertion each and eliminating the duplicates. http://gist.github.com/240457 I'm guessing the speed difference is due more to 1.8.2 v. 1.8.6 and the actual machines than any significant difference in our algorithms. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com