CalmoSoft primes: Difference between revisions

m
→‎{{header|Raku}}: Doh! Accidentally left off last prime in sliding window. Fixed
(Algol 68 stretch - corrected comment)
m (→‎{{header|Raku}}: Doh! Accidentally left off last prime in sliding window. Fixed)
Line 485:
 
=={{header|Raku}}==
{{incorrect|Raku|see talk page}}
Longest sliding window prime sums
 
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers;
 
sub sliding-window(@list, $window) { (^(+@list - $window)).map: { @list[$_ ..^ $_+$window] } }
 
for flat (1e2, 1e3, 1e4, 1e5).map: { (1, 2.5, 5) »×» $_ } -> $upto {
Line 499 ⟶ 498:
my @sums = @primes.&sliding-window($_).grep: { .sum.is-prime }
next unless @sums;
say "\nFor primes up to {$upto.Int.&cardinal}:\nLongest sequence of consecutive primes yielding a prime sum: elements: {comma 1+$_}";
for @sums { say " {join '...', .[0..5, *-5..*]».&comma».join(' + ')}, sum: {.sum.&comma}" }
last
Line 510 ⟶ 509:
 
For primes up to two hundred fifty:
Longest sequence of consecutive primes yielding a prime sum: elements: 4749
7 + 11 + 13 + 17 + 19 + 23 + 29...199227 + 211229 + 223233 + 227239 + 229241, sum: 5,107813
11 + 13 + 17 + 19 + 23 + 29...211 + 223 + 227 + 229 + 233, sum: 5,333
 
For primes up to five hundred:
Longest sequence of consecutive primes yielding a prime sum: elements: 8185
1131 + 1337 + 1741 + 1943 + 2347 + 2953...419467 + 421479 + 431487 + 433491 + 439499, sum: 1621,823407
19 + 23 + 29 + 31 + 37 + 41...433 + 439 + 443 + 449 + 457, sum: 18,131
29 + 31 + 37 + 41 + 43 + 47...443 + 449 + 457 + 461 + 463, sum: 19,013
 
For primes up to one thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 162163
213 + 317 + 519 + 723 + 1129 + 1331...929971 + 937977 + 941983 + 947991 + 953997, sum: 7076,241099
 
For primes up to two thousand, five hundred:
Line 538 ⟶ 534:
 
For primes up to twenty-five thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 2,757759
37 + 511 + 713 + 1117 + 1319 + 1723...24,919967 + 24,923971 + 24,943977 + 24,953979 + 24,967989, sum: 32,305405,799707
 
For primes up to fifty thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 5,125131
135 + 177 + 1911 + 2313 + 2917 + 3119...49,927943 + 49,937957 + 49,939991 + 49,943993 + 49,957999, sum: 120121,863013,297303
 
For primes up to one hundred thousand:
Line 550 ⟶ 546:
 
For primes up to two hundred fifty thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 22,037041
5 + 7 + 11 + 13 + 17 + 19 + 23...249,871947 + 249,881967 + 249,911971 + 249,923973 + 249,943989, sum: 2,621623,781031,299141
 
For primes up to five hundred thousand:
10,333

edits