From: Benoit Daloze Date: 2009-11-24T05:32:03+09:00 Subject: Re: Distinct Sets (#225) --0016e659fb26aa311804790f9ac0 Content-Type: text/plain; charset=ISO-8859-1 Hey Rubyists! I think I got quite a fast solution, using 1.9. Here is my test file : http://pastie.org/711737 You just need to change METHOD and require your own file So here is my best result for the 19tests: Finished in 0.222688 seconds. 1 tests, 19 assertions, 0 failures, 0 errors, 0 skips Without sorting(I just had to change the order of some tests of Rob) Maye I should also say I'm using a 64bit ruby 1.9.2 ? Anyway I think this method is far faster than my others(about 100 times) and probably some of yours. Enjoy the quiz, Benoit 2009/11/23 > On Mon, Nov 23, 2009 at 11:10 AM, Rob Biedenharn > wrote: > > On Nov 22, 2009, at 1:51 AM, lith wrote: > >>> http://gist.github.com/240457 > >> > >> Both of your tests use rather small input sets. It would be > >> interesting to know how the solutions deal with input that contains > >> many (10, 50, 100, ....) sets and/or many different signs (not just > >> letters). > > > > I accept your challenge! The gist has been updated with sets that use > > numbers and symbols as well as strings. There are also some tests of > large > > sets (which worked fine, but getting the test setup by hand was nasty). > > Thanks. > > > ruby1.8 -v -rubygems distinct_sets_test.rb > ruby 1.8.7 (2009-06-12 patchlevel 174) [i486-linux] > /var/lib/gems/1.8/gems/shoulda-2.10.2/lib/shoulda/context.rb:4: > warning: method redefined; discarding old contexts > Loaded suite distinct_sets_test > Started > ..................EEE..... > Finished in 3.424045 seconds. > > 1) Error: > test: non-uniform contents should handle matching on symbols. > (DistinctSetsTest): > ArgumentError: comparison of String with :bill failed > ./distinct_sets.rb:7:in `sort' > > 2) Error: > test: non-uniform contents should handle mix of strings and symbols > (matching on string). (DistinctSetsTest): > ArgumentError: comparison of String with :bill failed > ./distinct_sets.rb:7:in `sort' > > 3) Error: > test: non-uniform contents should handle mix of strings, numbers, and > symbols. (DistinctSetsTest): > ArgumentError: comparison of Fixnum with :emergency failed > ./distinct_sets.rb:7:in `sort' > > 26 tests, 175 assertions, 0 failures, 3 errors > > > The only change that I has to make was in how I sorted the final array to > > account for symbols or mixed contents: Numerics compare "naturally" with > <=> > > and non-numeric or mixed are compared using the #to_s representation. > > Simply not sorting: > > 26 tests, 202 assertions, 17 failures, 0 errors > > Simply sort_by{to_s}: > > 26 tests, 202 assertions, 3 failures, 0 errors > > More complex sort{}: > > 26 tests, 202 assertions, 0 failures, 0 errors > > --0016e659fb26aa311804790f9ac0--