CalmoSoft primes: Difference between revisions

Content added Content deleted
m (Moved C entry into correct alphabetic order.)
Line 680: Line 680:
Longest Calmo prime seq (length 21) of primes less than 100 is:
Longest Calmo prime seq (length 21) of primes less than 100 is:
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
[7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
</pre>
=== Stretch task ===
{{trans|Julia}}
<syntaxhighlight lang="python">""" rosettacode.org/wiki/CalmoSoft_prime """

from sympy import isprime, primerange


def calmo_prime_sequence(N=100, showsequence=True):
""" find the largest prime seq in primes < N that sums to a prime """
pri = list(primerange(N))
for window_size in range(len(pri)+1, 1, -1):
for i in range(len(pri)-window_size):
if isprime(sum(pri[i:i+window_size])):
print(
f'Longest Calmo prime seq (length {window_size}) of primes less than {N} totals {sum(pri[i:i+window_size])}')
if showsequence:
print("The sequence is: ", pri[i:i+window_size])
return


calmo_prime_sequence()
calmo_prime_sequence(50_000_000, False)
</syntaxhighlight>{{out}}
<pre>
Longest Calmo prime seq (length 21) of primes less than 100 totals 953
The sequence is: [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89]
Longest Calmo prime seq (length 3001117) of primes less than 50000000 totals 72618848632313
</pre>
</pre>