CalmoSoft primes: Difference between revisions
Content added Content deleted
m (→Stretch task) |
|||
Line 992: | Line 992: | ||
def calmo_prime_sequence( |
def calmo_prime_sequence(maxp): |
||
""" find the largest prime seq in primes < |
""" find the largest prime seq in primes < maxp that sums to a prime """ |
||
pri = list(primerange( |
pri = list(primerange(maxp)) |
||
for |
for w in range(len(pri)-1, 1, -1): |
||
psum = sum(pri[:w]) |
|||
for d in range(-1, len(pri)-w): |
|||
if d >= 0: |
|||
psum -= pri[d] |
|||
⚫ | |||
psum += pri[w + d] |
|||
if isprime(psum): |
|||
print('[', ', '.join(map(str, pri[i:i+6])), ', ... ', ', '.join(map(str, pri[i+window_size-6:i+window_size])), ']\n', sep='') |
|||
print('Longest Calmo prime seq (length', w, |
|||
⚫ | |||
if w > 24: |
|||
print(''.join(list(str(pri[d+1:d+6]))[:-2]), ", ... ", |
|||
''.join(list(str(pri[d-5+w:d+w]))[1:]), "\n") |
|||
else: |
else: |
||
print(pri[ |
print("The sequence is: ", pri[d+1:d+w+1], "\n") |
||
return |
return |
||
⚫ | |||
for pmax in [100, 500_000, 50_000_000]: |
|||
⚫ | |||
</syntaxhighlight>{{out}} |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Longest Calmo prime seq (length 21) of primes less than 100 totals 953 |
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] |
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 41530 ) of primes less than 500000 totals 9910236647 |
|||
⚫ | |||
[2, 3, 5, 7, 1 , ... 499787, 499801, 499819, 499853, 499879] |
|||
⚫ | |||
⚫ | |||
</pre> |
</pre> |
||