Good evening Steve,
Steve Wampler wrote:
> Bruce & Breeanna Rennie wrote:
>> Greetings to all for the new year,
>>
>> I have just been reading the paper by Melissa E. O'Neill called "The
>> Genuine Sieve of Eratosthenes." This paper was written from the
>> perspective of a functional programming paradigm. It got me thinking
>> about how to write the corresponding Icon/UnIcon program.
>>
>> Has anyone seen or done an Icon/UnIcon implementation of this
>> algorithm using co-expression?
>>
>> I am trying to build one now.
>
> How close is the attached? I wrote this as part of my dissertation back
> in the late 70's. It's a brute force sieve that adds co-expressions to
> the sieve as primes are discovered by the sieve.
>
Not close as your code is doing a division which is not needed only
additions, multiplication (for squaring a prime number) and some
comparisons.
What I have so far to get the initial list for testing is the following
in which all number produced prior to 121 are primes - using the wheel.
Icon code follows:::::
global wheel2357
global primes
global candidate
procedure main()
local nextcandidate, primecandidate, i
wheel2357 := create |( 2 | 4 | 2 | 4 | 6 | 2 | 6 | 4 |
2 | 4 | 6 | 6 | 2 | 6 | 4 | 2 |
6 | 4 | 6 | 8 | 4 | 2 | 4 | 2 |
4 | 8 | 6 | 4 | 6 | 2 | 4 | 6 |
2 | 6 | 6 | 4 | 2 | 4 | 6 | 2 |
6 | 4 | 2 | 4 | 2 | 10 | 2 | 10 )
primes := [2, 3, 5, 7]
candidate := create ( (nextcandidate := 11) | ( |( nextcandidate
+:= @wheel2357)))
i := 1
while (write( @candidate) & ((i +:= 1) <= 800))
end
Icon code finished.
The algorithm then seems to extract all numbers from the list candidates
that are less than the square of the current prime being looked at. It
removes the multiples of the current prime above the square of the prime.
I'm looking at the above statement and it makes less sense than I would
like. Trying to convert a functional language program to a
non-functional style can be a bit painful.
--
regards
Bruce Rennie
(God's Own Country Downunder)
Warragul. Victoria.
Australia.
------------------------------------------------------------------------------
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group