[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: newbie question about sets

Daniel Finnie

1/16/2007 12:01:00 AM

You shouldn't really have to avoid this. The 6 letter word should be 6
unique letters, otherwise how would there be 6 letters for the user to
guess?

Dan

Jason Mayer wrote:
> I'm just curious if there's any way to duplicate values in a set. After
> quiz 108, I modified my submission so that it was a fully functional game.
> I then passed around my finished program to some of my coworkers who are
> interested in ruby. After a few days, someone came back to me with a bug,
> and this appears to be the root cause of that bug.
>
> irb(main):001:0> target = "stuff"
> => "stuff"
> irb(main):002:0> a = target.split(//).sort
> => ["f", "f", "s", "t", "u"]
> irb(main):003:0> require 'Set'
> => true
> irb(main):004:0> s1 = Set.new(a)
> => #<Set: {"f", "s", "t", "u"}>
>
> As it stands, if the word ffffuuuuussssstttt existed, it would be
> considered
> a subset of a. How do you avoid this using sets?
>