Sisyphus sequence: Difference between revisions
→{{header|Python}}: Extreme stretch
m (→Extreme stretch (just a note about): added prebuilt note) |
(→{{header|Python}}: Extreme stretch) |
||
Line 374:
These numbers under 250 occur the most in the first 100,000,000 terms:
[28, 14, 7] all occur 7 times.
</pre>
===Extreme stretch===
Using Python bindings for the primesieve C++ library and PyPy 3.9 instead of CPython (PyPy is nearly twice as fast up to s(100,000,000)), this completed in about 1 hour and 53 minutes on a AMD Ryzen 5 1500X. Memory usage was minimal thanks to <code>primesieve.Iterator()</code>.
<syntaxhighlight lang="python">import primesieve
def sisyphus36():
primes = primesieve.Iterator()
n = 1
p = 0
i = 1
while True:
i += 1
if n % 2:
p = primes.next_prime()
n = n + p
else:
n = n // 2
if n == 36:
print(f"{i:,}, {n:,}, {p:,}")
break
if __name__ == "__main__":
sisyphus36()
</syntaxhighlight>
{{out}}
<pre>
$ time pypy3.9 sisyphus_36.py
77,534,485,877, 36, 677,121,348,413
real 113m2.636s
user 112m56.973s
sys 0m0.060s
</pre>
|