The sieve of Sundaram: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 27: | Line 27: | ||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="11l">F sieve_of_Sundaram(nth, print_all = 1B) |
||
‘ |
‘ |
||
The sieve of Sundaram is a simple deterministic algorithm for finding all the |
The sieve of Sundaram is a simple deterministic algorithm for finding all the |
||
Line 57: | Line 57: | ||
sieve_of_Sundaram(100, 1B) |
sieve_of_Sundaram(100, 1B) |
||
sieve_of_Sundaram(1000000, 0B)</ |
sieve_of_Sundaram(1000000, 0B)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 82: | Line 82: | ||
{{Trans|Nim}} |
{{Trans|Nim}} |
||
To run this with Algol 68G, you will need to increase the heap size by specifying e.g. <code>-heap=64M</code> on the command line. |
To run this with Algol 68G, you will need to increase the heap size by specifying e.g. <code>-heap=64M</code> on the command line. |
||
< |
<syntaxhighlight lang="algol68">BEGIN # sieve of Sundaram # |
||
INT n = 8 000 000; |
INT n = 8 000 000; |
||
INT none = 0, mark1 = 1, mark2 = 2; |
INT none = 0, mark1 = 1, mark2 = 2; |
||
Line 124: | Line 124: | ||
print( ( "The millionth Sundaram prime is ", whole( last, 0 ), newline ) ) |
print( ( "The millionth Sundaram prime is ", whole( last, 0 ), newline ) ) |
||
FI |
FI |
||
END</ |
END</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 144: | Line 144: | ||
The "nth prime" calculation here's gleaned from the Python and Julia solutions and the limitations to marking partly from the Phix. |
The "nth prime" calculation here's gleaned from the Python and Julia solutions and the limitations to marking partly from the Phix. |
||
< |
<syntaxhighlight lang="applescript">on sieveOfSundaram(indexRange) |
||
if (indexRange's class is list) then |
if (indexRange's class is list) then |
||
set n1 to beginning of indexRange |
set n1 to beginning of indexRange |
||
Line 230: | Line 230: | ||
end task |
end task |
||
task()</ |
task()</syntaxhighlight> |
||
{{output}} |
{{output}} |
||
< |
<syntaxhighlight lang="applescript">"1st to 100th Sundaram primes: |
||
3 5 7 11 13 17 19 23 29 31 |
3 5 7 11 13 17 19 23 29 31 |
||
37 41 43 47 53 59 61 67 71 73 |
37 41 43 47 53 59 61 67 71 73 |
||
Line 245: | Line 245: | ||
479 487 491 499 503 509 521 523 541 547 |
479 487 491 499 503 509 521 523 541 547 |
||
1,000,000th: |
1,000,000th: |
||
15485867"</ |
15485867"</syntaxhighlight> |
||
=={{header|C}}== |
=={{header|C}}== |
||
<syntaxhighlight lang="c"> |
|||
<lang C> |
|||
#include <stdio.h> |
#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
Line 278: | Line 278: | ||
} |
} |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 298: | Line 298: | ||
<strike>Generating prime numbers during sieve creation gives a performance boost over completing the sieve and then scanning the sieve for output. There are, of course, a few at the end to scan out.</strike><br/> |
<strike>Generating prime numbers during sieve creation gives a performance boost over completing the sieve and then scanning the sieve for output. There are, of course, a few at the end to scan out.</strike><br/> |
||
Heh, nope. It's faster to do the sieving first, then the generation afterwards. |
Heh, nope. It's faster to do the sieving first, then the generation afterwards. |
||
< |
<syntaxhighlight lang="csharp">using System; |
||
using System.Collections.Generic; |
using System.Collections.Generic; |
||
using System.Linq; |
using System.Linq; |
||
Line 340: | Line 340: | ||
yield return (v << 1) + 1; |
yield return (v << 1) + 1; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Under <strike>1/5</strike> <b><font color=darkgreen>1/8</font></b> of a second @ Tio.run |
Under <strike>1/5</strike> <b><font color=darkgreen>1/8</font></b> of a second @ Tio.run |
||
Line 359: | Line 359: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// The sieve of Sundaram. Nigel Galloway: August 7th., 2021 |
// The sieve of Sundaram. Nigel Galloway: August 7th., 2021 |
||
let sPrimes()= |
let sPrimes()= |
||
Line 372: | Line 372: | ||
sPrimes()|>Seq.take 100|>Seq.iter(printf "%d "); printfn "" |
sPrimes()|>Seq.take 100|>Seq.iter(printf "%d "); printfn "" |
||
printfn "The millionth Sundaram prime is %d" (Seq.item 999999 (sPrimes())) |
printfn "The millionth Sundaram prime is %d" (Seq.item 999999 (sPrimes())) |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 380: | Line 380: | ||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
<syntaxhighlight lang="fortran"> |
|||
<lang Fortran> |
|||
PROGRAM SUNDARAM |
PROGRAM SUNDARAM |
||
IMPLICIT NONE |
IMPLICIT NONE |
||
Line 436: | Line 436: | ||
END PROGRAM SUNDARAM |
END PROGRAM SUNDARAM |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 457: | Line 457: | ||
{{trans|Wren}} |
{{trans|Wren}} |
||
{{libheader|Go-rcu}} |
{{libheader|Go-rcu}} |
||
< |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 541: | Line 541: | ||
fmt.Printf("\nUsing the Sieve of Eratosthenes would have generated them in %s ms.\n", celapsed) |
fmt.Printf("\nUsing the Sieve of Eratosthenes would have generated them in %s ms.\n", celapsed) |
||
fmt.Printf("\nAs a check, the %s Sundaram prime would again have been %s\n", million, millionth) |
fmt.Printf("\nAs a check, the %s Sundaram prime would again have been %s\n", million, millionth) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 567: | Line 567: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.List (intercalate, transpose) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
import qualified Data.Set as S |
import qualified Data.Set as S |
||
Line 609: | Line 609: | ||
let ws = maximum . fmap length <$> transpose rows |
let ws = maximum . fmap length <$> transpose rows |
||
pw = printf . flip intercalate ["%", "s"] . show |
pw = printf . flip intercalate ["%", "s"] . show |
||
in unlines $ intercalate gap . zipWith pw ws <$> rows</ |
in unlines $ intercalate gap . zipWith pw ws <$> rows</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 100 Sundaram primes (starting at 3): |
<pre>First 100 Sundaram primes (starting at 3): |
||
Line 625: | Line 625: | ||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
< |
<syntaxhighlight lang="javascript">(() => { |
||
"use strict"; |
"use strict"; |
||
Line 732: | Line 732: | ||
return main(); |
return main(); |
||
})();</ |
})();</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First 100 Sundaram primes |
<pre>First 100 Sundaram primes |
||
Line 758: | Line 758: | ||
(*) For large sieves, gojq will consume a very large amount of memory. |
(*) For large sieves, gojq will consume a very large amount of memory. |
||
< |
<syntaxhighlight lang="jq"># `sieve_of_Sundaram` as defined here generates the stream of |
||
# consecutive primes from 3 on but less than or equal to the specified |
# consecutive primes from 3 on but less than or equal to the specified |
||
# limit specified by `.`. |
# limit specified by `.`. |
||
Line 795: | Line 795: | ||
elif $n <= 100 then ($n | 1.2 * . * log) | sieve |
elif $n <= 100 then ($n | 1.2 * . * log) | sieve |
||
else $n | (1.15 * . * log) | sieve # OK |
else $n | (1.15 * . * log) | sieve # OK |
||
end;</ |
end;</syntaxhighlight> |
||
'''For pretty-printing''' |
'''For pretty-printing''' |
||
< |
<syntaxhighlight lang="jq">def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .; |
||
def nwise($n): |
def nwise($n): |
||
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end; |
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end; |
||
n;</ |
n;</syntaxhighlight> |
||
'''The Tasks''' |
'''The Tasks''' |
||
< |
<syntaxhighlight lang="jq">def hundred: |
||
Sundaram_primes(100) |
Sundaram_primes(100) |
||
| nwise(10) |
| nwise(10) |
||
Line 810: | Line 810: | ||
"First hundred:", hundred, |
"First hundred:", hundred, |
||
"\nMillionth is \(Sundaram_primes(1000000)[-1])"</ |
"\nMillionth is \(Sundaram_primes(1000000)[-1])"</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 831: | Line 831: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
< |
<syntaxhighlight lang="julia"> |
||
""" |
""" |
||
The sieve of Sundaram is a simple deterministic algorithm for finding all the |
The sieve of Sundaram is a simple deterministic algorithm for finding all the |
||
Line 870: | Line 870: | ||
using Primes; @show count(primesmask(15485867)) |
using Primes; @show count(primesmask(15485867)) |
||
@time count(primesmask(15485867)) |
@time count(primesmask(15485867)) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
3 5 7 11 13 17 19 23 29 31 |
3 5 7 11 13 17 19 23 29 31 |
||
Line 894: | Line 894: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">ClearAll[SieveOfSundaram] |
||
SieveOfSundaram[n_Integer] := Module[{i, prefac, k, ints}, |
SieveOfSundaram[n_Integer] := Module[{i, prefac, k, ints}, |
||
k = Floor[(n - 2)/2]; |
k = Floor[(n - 2)/2]; |
||
Line 909: | Line 909: | ||
] |
] |
||
SieveOfSundaram[600][[;; 100]] |
SieveOfSundaram[600][[;; 100]] |
||
SieveOfSundaram[16000000][[10^6]]</ |
SieveOfSundaram[16000000][[10^6]]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547} |
<pre>{3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547} |
||
Line 915: | Line 915: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import strutils |
||
const N = 8_000_000 |
const N = 8_000_000 |
||
Line 957: | Line 957: | ||
if last == 0: |
if last == 0: |
||
quit "Not enough values in sieve. Found only $#.".format(count), QuitFailure |
quit "Not enough values in sieve. Found only $#.".format(count), QuitFailure |
||
echo "The millionth Sundaram prime is ", ($last).insertSep()</ |
echo "The millionth Sundaram prime is ", ($last).insertSep()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 975: | Line 975: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 1,002: | Line 1,002: | ||
(say "One millionth: " . (1+2*$index)) and last if $count == $nth; |
(say "One millionth: " . (1+2*$index)) and last if $count == $nth; |
||
++$index; |
++$index; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First 100 Sundaram primes: |
<pre>First 100 Sundaram primes: |
||
Line 1,019: | Line 1,019: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">sos</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">sos</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span> |
||
Line 1,046: | Line 1,046: | ||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 100 odd prime numbers:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">100</span><span style="color: #0000FF;">]}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first 100 odd prime numbers:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%3d"</span><span style="color: #0000FF;">},</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..</span><span style="color: #000000;">100</span><span style="color: #0000FF;">]}),</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)})</span> |
||
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The millionth odd prime number: %,d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1_000_000</span><span style="color: #0000FF;">]})</span> |
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The millionth odd prime number: %,d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">s</span><span style="color: #0000FF;">[</span><span style="color: #000000;">1_000_000</span><span style="color: #0000FF;">]})</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,066: | Line 1,066: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
===Python :: Procedural=== |
===Python :: Procedural=== |
||
< |
<syntaxhighlight lang="python">from numpy import log |
||
def sieve_of_Sundaram(nth, print_all=True): |
def sieve_of_Sundaram(nth, print_all=True): |
||
Line 1,101: | Line 1,101: | ||
sieve_of_Sundaram(1000000, False) |
sieve_of_Sundaram(1000000, False) |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
3 5 7 11 13 17 19 23 29 31 |
3 5 7 11 13 17 19 23 29 31 |
||
Line 1,121: | Line 1,121: | ||
===Python :: Functional=== |
===Python :: Functional=== |
||
Composing functionally, and obtaining slightly better performance by defining a set (rather than list) of exclusions. |
Composing functionally, and obtaining slightly better performance by defining a set (rather than list) of exclusions. |
||
< |
<syntaxhighlight lang="python">'''Sieve of Sundaram''' |
||
from math import floor, log, sqrt |
from math import floor, log, sqrt |
||
Line 1,205: | Line 1,205: | ||
# MAIN --- |
# MAIN --- |
||
if __name__ == '__main__': |
if __name__ == '__main__': |
||
main()</ |
main()</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>First hundred Sundaram primes, starting at 3: |
<pre>First hundred Sundaram primes, starting at 3: |
||
Line 1,229: | Line 1,229: | ||
{{trans|xxx}} |
{{trans|xxx}} |
||
< |
<syntaxhighlight lang="racket">#lang racket |
||
(define (make-sieve-as-set limit) |
(define (make-sieve-as-set limit) |
||
Line 1,254: | Line 1,254: | ||
(module+ main |
(module+ main |
||
(Sieve-of-Sundaram))</ |
(Sieve-of-Sundaram))</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,262: | Line 1,262: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>my $nth = 1_000_000; |
||
my $k = Int.new: 2.4 * $nth * log($nth) / 2; |
my $k = Int.new: 2.4 * $nth * log($nth) / 2; |
||
Line 1,289: | Line 1,289: | ||
say $index * 2 + 1 and last if $count == $nth; |
say $index * 2 + 1 and last if $count == $nth; |
||
++$index; |
++$index; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>First 100 Sundaram primes: |
<pre>First 100 Sundaram primes: |
||
Line 1,309: | Line 1,309: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
For the calculation of the 1,000,000<sup>th</sup> Sundaram prime, it requires a 64-bit version of REXX. |
For the calculation of the 1,000,000<sup>th</sup> Sundaram prime, it requires a 64-bit version of REXX. |
||
< |
<syntaxhighlight lang="rexx">/*REXX program finds & displays N Sundaram primes, or displays the Nth Sundaram prime.*/ |
||
parse arg n cols . /*get optional number of primes to find*/ |
parse arg n cols . /*get optional number of primes to find*/ |
||
if n=='' | n=="," then n= 100 /*Not specified? Then assume default.*/ |
if n=='' | n=="," then n= 100 /*Not specified? Then assume default.*/ |
||
Line 1,341: | Line 1,341: | ||
exit 0 /*stick a fork in it, we're all done. */ |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</ |
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,367: | Line 1,367: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Based on the Python code from the Wikipedia lemma. |
Based on the Python code from the Wikipedia lemma. |
||
< |
<syntaxhighlight lang="ruby">def sieve_of_sundaram(upto) |
||
n = (2.4 * upto * Math.log(upto)) / 2 |
n = (2.4 * upto * Math.log(upto)) / 2 |
||
k = (n - 3) / 2 + 1 |
k = (n - 3) / 2 + 1 |
||
Line 1,382: | Line 1,382: | ||
n = 1_000_000 |
n = 1_000_000 |
||
puts "\nThe #{n}th sundaram prime is #{sieve_of_sundaram(n)[n-1]}" |
puts "\nThe #{n}th sundaram prime is #{sieve_of_sundaram(n)[n-1]}" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547] |
<pre>[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547] |
||
Line 1,392: | Line 1,392: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
I've worked here from the second (optimized) Python example in the Wikipedia article for SOS which allows an easy transition to an 'odds only' SOE for comparison. |
I've worked here from the second (optimized) Python example in the Wikipedia article for SOS which allows an easy transition to an 'odds only' SOE for comparison. |
||
< |
<syntaxhighlight lang="ecmascript">import "/fmt" for Fmt |
||
import "/seq" for Lst |
import "/seq" for Lst |
||
Line 1,455: | Line 1,455: | ||
elapsed = ((System.clock - start) * 1000).round |
elapsed = ((System.clock - start) * 1000).round |
||
Fmt.print("\nUsing the Sieve of Eratosthenes would have generated them in $,d ms.", elapsed) |
Fmt.print("\nUsing the Sieve of Eratosthenes would have generated them in $,d ms.", elapsed) |
||
Fmt.print("\nAs a check, the $,d Sundaram prime would again have been $,d", 1e6, primes[1e6-1])</ |
Fmt.print("\nAs a check, the $,d Sundaram prime would again have been $,d", 1e6, primes[1e6-1])</syntaxhighlight> |
||
{{out}} |
{{out}} |