CalmoSoft primes: Difference between revisions
Content added Content deleted
Tag: Undo |
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 win in range(len(pri)-1, 1, -1): # window size |
||
psum = sum(pri[:win]) |
|||
for bot in range(-1, len(pri)-win): # the last bottom of window |
|||
⚫ | |||
if bot >= 0: |
|||
psum -= pri[bot] |
|||
⚫ | |||
psum += pri[win + bot] |
|||
⚫ | |||
⚫ | |||
print('Longest Calmo prime seq (length', win, |
|||
') of primes less than', maxp, 'totals', sum(pri[bot+1:bot+win+1])) |
|||
if win > 24: |
|||
⚫ | |||
', '.join(map(str, pri[bot-5+win:bot+win+1])), ']\n', sep='') |
|||
else: |
else: |
||
print(pri[ |
print('The sequence is:', pri[bot+1:bot+win+1], '\n') |
||
return |
return |
||
for pmax in [100, 500_000, 50_000_000]: |
|||
calmo_prime_sequence() |
|||
calmo_prime_sequence( |
calmo_prime_sequence(pmax) |
||
</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: |
The sequence is: [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89] |
||
⚫ | |||
⚫ | |||
[2, 3, 5, 7, 11, 13, ... 499787, 499801, 499819, 499853, 499879, 499883] |
|||
⚫ | |||
[7, 11, 13, 17, 19, 23, ... 49999699, 49999711, 49999739, 49999751, 49999753, 49999757] |
[7, 11, 13, 17, 19, 23, ... 49999699, 49999711, 49999739, 49999751, 49999753, 49999757] |
||
</pre> |
</pre> |