Fwd: Sieve of Eratosthenes
Gil Egozi
gil.egozi at gmail.com
Tue Oct 10 03:01:26 UTC 2006
Hi,
I am resending this since i wan't a member, and the message is still
somewhere in moderation-land.
after looking at Ramon's version i noticed the java version isn't returning
the primes, so we can remove the last select:
this cuts time in half down close to: 500
Integer>>sieveOfEratosthenes
"generates primes up to self, educational algorithm, not for
production use"
| primes |
primes := ByteArray new: self.
2 to: self do: [:each |
(primes at: each) = 0 ifTrue: [each + each to: self
by: each do: [:notPrime |
primes at: notPrime put: 1]]].
"-------------"
SmalltalkImage current snapshot: true andQuit: false
Smalltalk garbageCollect.
Smalltalk garbageCollect.
Smalltalk garbageCollect. "force full garbage collect"
Time millisecondsToRun: [1000000 sieveOfEratosthenes].
Gil
--
Many people would sooner die than think; In fact, they do so.
-- Bertrand Russell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20061010/6f9ec278/attachment.htm
More information about the Squeak-dev
mailing list
|