CalmoSoft primes: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Incorporates two optimizations (see Talk Page) - about 20% faster than before.)
Line 1,014: Line 1,014:
{{libheader|Wren-math}}
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-fmt}}
This runs in about 4.3 seconds (cf. Julia 1.3 seconds) on my Core i7 machine. However, 2.6 seconds of that is needed to sieve for primes up to 50 million.
This runs in about 3.5 seconds (cf. Julia 1.3 seconds) on my Core i7 machine. However, 2.6 seconds of that is needed to sieve for primes up to 50 million.
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./fmt"for Fmt
import "./fmt"for Fmt
Line 1,031: Line 1,031:
if (pc - i < longest) break
if (pc - i < longest) break
if (i > 0) sum = sum - primes[i-1]
if (i > 0) sum = sum - primes[i-1]
var isEven = (i == 0)
var sum2 = sum
var sum2 = sum
for (j in pc-1..i) {
for (j in pc-1..i) {
var temp = j - i + 1
var temp = j - i + 1
if (temp < longest) break
if (temp < longest) break
if (j < pc -1) sum2 = sum2 - primes[j+1]
if (j < pc - 1) sum2 = sum2 - primes[j+1]
if (Int.isPrime(sum2)) {
if ((temp % 2) == 0 != isEven) continue
if (Int.isPrime2(sum2)) {
if (temp > longest) {
if (temp > longest) {
longest = temp
longest = temp