A question about sets

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

A question about sets

Fabian Boucsein-2
Hi there,

i am new to Smalltalk and Pharo and today, while
trying out some examples, i observed an somewhat
strange behaviour.

I used this snippet from the pharo.org website:

| numbers |
numbers := Set new.
10 timesRepeat: [ numbers add: 100 atRandom ].
numbers explore.

Using Pharo 3.0 on my Laptop with Manjaro Linux 32bit and copy
pasting the snippet above into the workspace i get sometimes
a set with 10 values, sometimes with 9 values and once a set
with just 8 values.

Using this snippet, just to test the timesRepeat message:
10 timesRepeat: [ Transcript show: (100 atRandom); cr. ].
i always get 10 values.

Is the behaviour with the first snippet correct? Giving sometimes
10 or 9 or even 8 values. Or is it a bug? I would expect to always
get 10 values in my set.

By the way i am totally excited about your cool programming
environment. Keep on the good work. I justed started to explore
it and can say it is awesome to work with.

Kind regards,
Fabian

Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Luc Fabresse
Hi Fabian,

Welcome on board ;-)

Set: I represent a set of objects without duplicates. 
so if you have the same number multiple times, it cannot be added more than once in the Set.

replace Set by Bag (I represent an unordered collection of possibly duplicate elements.) and the size will  always be 10.

Best,

Luc



#Luc


2014-06-14 11:48 GMT+02:00 Fabian Boucsein <[hidden email]>:
Hi there,

i am new to Smalltalk and Pharo and today, while
trying out some examples, i observed an somewhat
strange behaviour.

I used this snippet from the pharo.org website:

| numbers |
numbers := Set new.
10 timesRepeat: [ numbers add: 100 atRandom ].
numbers explore.

Using Pharo 3.0 on my Laptop with Manjaro Linux 32bit and copy
pasting the snippet above into the workspace i get sometimes
a set with 10 values, sometimes with 9 values and once a set
with just 8 values.

Using this snippet, just to test the timesRepeat message:
10 timesRepeat: [ Transcript show: (100 atRandom); cr. ].
i always get 10 values.

Is the behaviour with the first snippet correct? Giving sometimes
10 or 9 or even 8 values. Or is it a bug? I would expect to always
get 10 values in my set.

By the way i am totally excited about your cool programming
environment. Keep on the good work. I justed started to explore
it and can say it is awesome to work with.

Kind regards,
Fabian


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Tim Hendriks
In reply to this post by Fabian Boucsein-2
In sets there can be only Unique nummers. So random produced a few of the same numbers. They get excluded from the set.

Tim


Op 14 jun. 2014 om 11:48 heeft Fabian Boucsein <[hidden email]> het volgende geschreven:

Hi there,

i am new to Smalltalk and Pharo and today, while
trying out some examples, i observed an somewhat
strange behaviour.

I used this snippet from the pharo.org website:

| numbers |
numbers := Set new.
10 timesRepeat: [ numbers add: 100 atRandom ].
numbers explore.

Using Pharo 3.0 on my Laptop with Manjaro Linux 32bit and copy
pasting the snippet above into the workspace i get sometimes
a set with 10 values, sometimes with 9 values and once a set
with just 8 values.

Using this snippet, just to test the timesRepeat message:
10 timesRepeat: [ Transcript show: (100 atRandom); cr. ].
i always get 10 values.

Is the behaviour with the first snippet correct? Giving sometimes
10 or 9 or even 8 values. Or is it a bug? I would expect to always
get 10 values in my set.

By the way i am totally excited about your cool programming
environment. Keep on the good work. I justed started to explore
it and can say it is awesome to work with.

Kind regards,
Fabian

Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Ben Coman
In reply to this post by Fabian Boucsein-2
Fabian Boucsein wrote:
Hi there,

i am new to Smalltalk and Pharo and today, while
trying out some examples, i observed an somewhat
strange behaviour.

I used this snippet from the pharo.org website:

| numbers |
numbers := Set new.
10 timesRepeat: [ numbers add: 100 atRandom ].
numbers explore.

Using Pharo 3.0 on my Laptop with Manjaro Linux 32bit and copy
pasting the snippet above into the workspace i get sometimes
a set with 10 values, sometimes with 9 values and once a set
with just 8 values.

Using this snippet, just to test the timesRepeat message:
10 timesRepeat: [ Transcript show: (100 atRandom); cr. ].
i always get 10 values.

Is the behaviour with the first snippet correct? Giving sometimes
10 or 9 or even 8 values. Or is it a bug? I would expect to always
get 10 values in my set.

By the way i am totally excited about your cool programming
environment. Keep on the good work. I justed started to explore
it and can say it is awesome to work with.

Kind regards,
Fabian

Glad to hear you kind words.   A Set is an unordered collection without duplicates, so adding the same number a second time does not increase the element count.  The following code will make it obvious when you compare the number of duplicates in the Transcript with the contents of the Set.

| numbers |
numbers := Set new.
10 timesRepeat:
[   | rand |
    rand := 100 atRandom.
    Transcript crShow: rand.
    numbers add: rand.
].
numbers explore.


cheers -ben
Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Hilaire Fernandes-6
In reply to this post by Fabian Boucsein-2
Hi Fabien,

As other already explained, you just discovered the marvelous Set
collection.

Hilaire

Le 14/06/2014 11:48, Fabian Boucsein a écrit :
> i am new to Smalltalk and Pharo and today, while
> trying out some examples, i observed an somewhat
> strange behaviour.

--
Dr. Geo http://drgeo.eu
iStoa - https://launchpad.net/istoa


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Alain Busser
Hi Fabien and welcome,

you just discovered this phenomenon: http://en.wikipedia.org/wiki/Birthday_problem

and you can be proud having discovered it by yourself!

Alain


On Sun, Jun 15, 2014 at 12:12 AM, Hilaire Fernandes <[hidden email]> wrote:
Hi Fabien,

As other already explained, you just discovered the marvelous Set
collection.

Hilaire

Le 14/06/2014 11:48, Fabian Boucsein a écrit :
> i am new to Smalltalk and Pharo and today, while
> trying out some examples, i observed an somewhat
> strange behaviour.

--
Dr. Geo http://drgeo.eu
iStoa - https://launchpad.net/istoa



Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

hilaire
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Alain Busser
About the birthday problem, I already pulished something that I had exeperimented in the classroom, but it is in French: http://irem.univ-reunion.fr/spip.php?article618 (clic on "problème des anniversaires" tab). The idea is that if you add say 30 times a "365 atRandom" to a bag (instead of a set) it happens now and then that a number appear more than once. In this classroom, two students actually had the same birthday, and they were eager to know of it happens often, so that they were very active for this exercise.

Happy reading ;-)

Alain


On Wed, Jun 25, 2014 at 12:10 PM, hilaire <[hidden email]> wrote:
Alain,

I love very much your cultural insight and I would like to see more examples
like this one applied to Dr. Geo scripting or Smalltalk sketches.
Personally, I don't have the time to both develop Dr. Geo *and* to
investigate such examples; contributions like yours are more than welcome.

Thanks

Hilaire



--
View this message in context: http://forum.world.st/A-question-about-sets-tp4763094p4764640.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Hilaire Fernandes-6
Great!
Now I wonder how it could be used within Dr. Geo.

Thanks

Hilaire

Le 25/06/2014 18:33, Alain Busser a écrit :

> About the birthday problem, I already pulished something that I had
> exeperimented in the classroom, but it is in French:
> http://irem.univ-reunion.fr/spip.php?article618 (clic on "problème des
> anniversaires" tab). The idea is that if you add say 30 times a "365
> atRandom" to a bag (instead of a set) it happens now and then that a
> number appear more than once. In this classroom, two students actually
> had the same birthday, and they were eager to know of it happens often,
> so that they were very active for this exercise.
>
> Happy reading ;-)
>
> Alain
>
>
> On Wed, Jun 25, 2014 at 12:10 PM, hilaire
> <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Alain,
>
>     I love very much your cultural insight and I would like to see more
>     examples
>     like this one applied to Dr. Geo scripting or Smalltalk sketches.
>     Personally, I don't have the time to both develop Dr. Geo *and* to
>     investigate such examples; contributions like yours are more than
>     welcome.
>
>     Thanks
>
>     Hilaire
>
>
>
>     --
>     View this message in context:
>     http://forum.world.st/A-question-about-sets-tp4763094p4764640.html
>     Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>

--
Dr. Geo http://drgeo.eu
iStoa - https://launchpad.net/istoa


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Alain Busser
About the use of sets I found another idea: Eratosthene's sieve.

Basically you create a set containing all integers from 2 to, say, 200.

Then, beginning with 2, you choose remove all multiples of the number you choose from the set. Then you go to the next number in the set and so on...

The difficulty is to choose the right collection, as a set is not ordered and it is not easy to loop on the prime divisors...

I made it on this article (near the middle): http://irem.univ-reunion.fr/spip.php?article742

Of course you can have the set of primes directly under Pharo with isPrime as we did here: http://www.epi.asso.fr/revue/articles/a1211b.htm (I had forgotten this)

Alain


On Thu, Jun 26, 2014 at 8:21 PM, Hilaire Fernandes <[hidden email]> wrote:
Great!
Now I wonder how it could be used within Dr. Geo.

Thanks

Hilaire

Le 25/06/2014 18:33, Alain Busser a écrit :
> About the birthday problem, I already pulished something that I had
> exeperimented in the classroom, but it is in French:
> http://irem.univ-reunion.fr/spip.php?article618 (clic on "problème des
> anniversaires" tab). The idea is that if you add say 30 times a "365
> atRandom" to a bag (instead of a set) it happens now and then that a
> number appear more than once. In this classroom, two students actually
> had the same birthday, and they were eager to know of it happens often,
> so that they were very active for this exercise.
>
> Happy reading ;-)
>
> Alain
>
>
> On Wed, Jun 25, 2014 at 12:10 PM, hilaire
> <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Alain,
>
>     I love very much your cultural insight and I would like to see more
>     examples
>     like this one applied to Dr. Geo scripting or Smalltalk sketches.
>     Personally, I don't have the time to both develop Dr. Geo *and* to
>     investigate such examples; contributions like yours are more than
>     welcome.
>
>     Thanks
>
>     Hilaire
>
>
>
>     --
>     View this message in context:
>     http://forum.world.st/A-question-about-sets-tp4763094p4764640.html
>     Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

hilaire
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Alain Busser
You're right but it should not have a fixed length because I want to remove numbers from it. I guess an SortedCollection is the best way to retrieve the next prime number. And the exercise is a good way to discover select and reject...

Alain


On Fri, Jun 27, 2014 at 1:41 PM, hilaire <[hidden email]> wrote:
Why do you need a set for that? An array is enough.
But please go on.

Hilaire



--
View this message in context: http://forum.world.st/A-question-about-sets-tp4763094p4765282.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

philippeback
In reply to this post by Alain Busser

Fun French Smalltalk.

Il y a une version dispo?

Phil

Le 25 juin 2014 18:33, "Alain Busser" <[hidden email]> a écrit :
About the birthday problem, I already pulished something that I had exeperimented in the classroom, but it is in French: http://irem.univ-reunion.fr/spip.php?article618 (clic on "problème des anniversaires" tab). The idea is that if you add say 30 times a "365 atRandom" to a bag (instead of a set) it happens now and then that a number appear more than once. In this classroom, two students actually had the same birthday, and they were eager to know of it happens often, so that they were very active for this exercise.

Happy reading ;-)

Alain


On Wed, Jun 25, 2014 at 12:10 PM, hilaire <[hidden email]> wrote:
Alain,

I love very much your cultural insight and I would like to see more examples
like this one applied to Dr. Geo scripting or Smalltalk sketches.
Personally, I don't have the time to both develop Dr. Geo *and* to
investigate such examples; contributions like yours are more than welcome.

Thanks

Hilaire



--
View this message in context: http://forum.world.st/A-question-about-sets-tp4763094p4764640.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

Alain Busser
btw I still plan to port it to Pharo3...

Alain


On Sat, Jun 28, 2014 at 10:24 AM, [hidden email] <[hidden email]> wrote:

Fun French Smalltalk.

Il y a une version dispo?

Phil

Le 25 juin 2014 18:33, "Alain Busser" <[hidden email]> a écrit :

About the birthday problem, I already pulished something that I had exeperimented in the classroom, but it is in French: http://irem.univ-reunion.fr/spip.php?article618 (clic on "problème des anniversaires" tab). The idea is that if you add say 30 times a "365 atRandom" to a bag (instead of a set) it happens now and then that a number appear more than once. In this classroom, two students actually had the same birthday, and they were eager to know of it happens often, so that they were very active for this exercise.

Happy reading ;-)

Alain


On Wed, Jun 25, 2014 at 12:10 PM, hilaire <[hidden email]> wrote:
Alain,

I love very much your cultural insight and I would like to see more examples
like this one applied to Dr. Geo scripting or Smalltalk sketches.
Personally, I don't have the time to both develop Dr. Geo *and* to
investigate such examples; contributions like yours are more than welcome.

Thanks

Hilaire



--
View this message in context: http://forum.world.st/A-question-about-sets-tp4763094p4764640.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: A question about sets

hilaire
CONTENTS DELETED
The author has deleted this message.