Jump to content

Sisyphus sequence: Difference between revisions

→‎{{header|Wren}}: Added extreme stretch goal.
(→‎{{header|Wren}}: Added extreme stretch goal.)
Line 709:
No option here but to use a sieve as relying on the 'nextPrime' method would be far too slow to achieve the stretch goal in a reasonable time using Wren. Sieve limit found by experimentation.
 
Extreme stretch not attempted and probably out of thereasonable questionreach for Wren-CLI.
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./fmt" for Fmt
Line 781:
These numbers under 250 occur the most in the first 100,000,000 terms:
[7, 14, 28] all occur 7 times.
</pre>
 
===Extreme Stretch===
{{libheader|Wren-psieve}}
The above module provides Wren bindings for the very fast C++ library ''primesieve'', used by several other languages for this task, though we need to use a special executable (written in C) to run it at the present time - it cannot be run under Wren-CLI.
 
The following script manages to find the first occurrence of the number 36 in the sequence in about 2 hours 54 minutes which (relative to Phix) is much quicker than one would normally expect. This is probably due to the heavy lifting (i.e. the prime generation) being done here in both cases by C++ though this will tempered by the need to convert unsigned 64-bit integers to doubles (Wren's only numeric type) for each prime generated.
<syntaxhighlight lang="ecmascript">import "./psieve" for Primes
import "./fmt" for Fmt
 
var it = Primes.iter()
var n = 1
var count = 1
var prime
var target = 36
while (true) {
if (n % 2 == 1) {
prime = it.next
n = n + prime
} else {
n = n / 2
}
count = count + 1
if (n == target) {
Fmt.print("$,r member is: $d and highest prime needed: $,d", count, target, prime)
return
}
}</syntaxhighlight>
 
{{out}}
<pre>
77,534,485,877th member is: 36 and highest prime needed: 677,121,348,413
</pre>
9,487

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.