The sieve of Sundaram: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
The sieve of |
The sieve of Eratosthenes: you've been there; done that; have the T-shirt. The sieve of Eratosthenes was ancient history when Euclid was a schoolboy. You are ready for something less than 3000 years old. You are ready for The sieve of Sundaram. |
||
Starting with the ordered set of +ve integers, mark every third starting at 4 (4;7;10...). |
Starting with the ordered set of +ve integers, mark every third starting at 4 (4;7;10...). |
||
Line 18: | Line 18: | ||
Using your function find and output the first 100 and the millionth Sundaram prime. |
Using your function find and output the first 100 and the millionth Sundaram prime. |
||
The faithless amongst you may compare the results with those generated by The sieve of |
The faithless amongst you may compare the results with those generated by The sieve of Eratosthenes. |
||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
<lang fsharp> |
<lang fsharp> |
||
// The sieve of |
// The sieve of Sundaram. Nigel Galloway: August 7th., 2021 |
||
let sPrimes()= |
let sPrimes()= |
||
let sSieve=System.Collections.Generic.Dictionary<int,(unit -> int) list>() |
let sSieve=System.Collections.Generic.Dictionary<int,(unit -> int) list>() |
||
Line 33: | Line 33: | ||
sPrimes()|>Seq.take 100|>Seq.iter(printf "%d "); printfn "" |
sPrimes()|>Seq.take 100|>Seq.iter(printf "%d "); printfn "" |
||
printfn "The millionth |
printfn "The millionth Sundaram prime is %d" (Seq.item 999999 (sPrimes())) |
||
</lang> |
</lang> |
||
{{out}} |
{{out}} |