# Re: Counting Toothpicks (#111)

**URL:** <https://www.ruby-forum.com/t/re-counting-toothpicks-111/83815>\
**Category:** Ruby\
**Created:** [January 29, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/re-counting-toothpicks-111/83815 "2007-01-29T23:17:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [January 29, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/re-counting-toothpicks-111/83815/1 "2007-01-29T23:17:00Z")

</div>

I have a fairly verbose submission for this quiz. It’s probably quite  
slow compared to others, but at least I can follow my own code 🙂 One  
question for the more advanced rubyists - I use sets in one place, and  
tried to unit test the results, but Set.== didn’t perform as I would  
have expected… for instance:

require ‘set’  
s1 = Set.new  
s1 \<\< {1=\>2}  
s1 \<\< {2=\>3}  
s2 = Set.new  
s2 \<\< {1=\>2}  
s2 \<\< {2=\>3}  
s1 == s2

is false. Presumably this is due to reference v.s. values equality, but  
I thought that since Hash defines values-based ==, Set.== would use it,  
but it appears not. This is somewhat surprising, I’ll warrant.

Oh, and what’s the preferred submission method - attachment, inclusion,  
or pastie?

- donald

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [January 29, 2007, 11:57pm UTC](https://www.ruby-forum.com/t/re-counting-toothpicks-111/83815/2 "2007-01-29T23:57:07Z")

</div>

Ball, Donald A Jr (Library):

> One question for the more advanced rubyists

Let a newbie answer. 🙂 For a similar question, see my â€˜Sane  
#hash implementation?â€™ mail sent just a couple minutes ago.

> I use sets in one place, and tried to unit test the results, but  
> Set.== didn’t perform as I would have expected… for instance:

Set#== performs as advertised.

> > Set.new == Set.new  
> > =\> true
> 
> > Set.new([1,2]) == Set.new([1,2])  
> > =\> true

> require ‘set’  
> s1 = Set.new  
> s1 \<\< {1=\>2}  
> s1 \<\< {2=\>3}  
> s2 = Set.new  
> s2 \<\< {1=\>2}  
> s2 \<\< {2=\>3}  
> s1 == s2

> is false.

> I thought that since Hash defines values-based ==,  
> Set.== would use it, but it appears not.

Set#== docs say, â€˜the equality of each couple of elements  
is defined according to Object#eql?,â€™ and seem to be right:

> > Hash.new({1=\>2}).eql? Hash.new({1=\>2})  
> > =\> false

– Shot

---

<div class="post-metadata">

**Author:** ![BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/da6949/32.png) [@BallS\_Donald\_A\_Jr\_S](https://www.ruby-forum.com/u/BallS_Donald_A_Jr_S)\
**Post date:** [January 30, 2007, 12:07am UTC](https://www.ruby-forum.com/t/re-counting-toothpicks-111/83815/3 "2007-01-30T00:07:08Z")

</div>

On Jan 29, 2007, at 4:16 PM, Ball, Donald A Jr (Library) wrote:

> Oh, and what’s the preferred submission method - attachment,  
> inclusion,  
> or pastie?

I personally think inline code is the best for the purposes of the  
archives.

I’ve enjoyed the habit some are getting into by providing the pastie  
link as an option though. With that, syntax highlighting is only a  
click away and I can download your source without email reformatting  
concerns.

I’m pretty easy going though and try to accept everything.

James Edward G. II
