Twin primes: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(2 intermediate revisions by 2 users not shown)
Line 1,372:
The time complexity here is all about building a table of primes. It turns out that using the builtin get_prime() is actually faster
than using an explicit sieve (as per Delphi/Go/Wren) due to retaining all the intermediate 0s, not that I particularly expect this to win any performance trophies.
<!--(phixonline)-->
<syntaxhighlight lang="phix">
with javascript_semantics
Line 1,601 ⟶ 1,602:
my $p = Math::Primesieve.new;
 
printf "Twin prime pairs less than %14s17s: %s\n", comma(10**$_), comma $p.count(10**$_, :twins) for 1 .. 1012;</syntaxhighlight>
say (now - INIT now).round(.01) ~ ' seconds';</syntaxhighlight>
{{out}}
<pre>Twin prime pairs less than 10: 2
Twin prime pairs less than 100: 8
Twin prime pairs less than 1,000: 35
Twin prime pairs less than 10,000: 205
Twin prime pairs less than 100,000: 1,224
Twin prime pairs less than 1,000,000: 8,169
Twin prime pairs less than 10,000,000: 58,980
Twin prime pairs less than 100,000,000: 440,312
Twin prime pairs less than 1,000,000,000: 3,424,506
Twin prime pairs less than 10,000,000,000: 27,412,679</pre>
Twin prime pairs less than 100,000,000,000: 224,376,048
Twin prime pairs less than 1,000,000,000,000: 1,870,585,220
6.89 seconds</pre>
 
=={{header|REXX}}==
Line 1,950 ⟶ 1,955:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
var c = Int.primeSieve(1e8-1, false)
9,482

edits