CalmoSoft primes: Difference between revisions

Content added Content deleted
(Algol 68 stretch - corrected comment)
m (→‎{{header|Raku}}: Doh! Accidentally left off last prime in sliding window. Fixed)
Line 485: Line 485:


=={{header|Raku}}==
=={{header|Raku}}==
{{incorrect|Raku|see talk page}}
Longest sliding window prime sums
Longest sliding window prime sums


<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers;
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers;


sub sliding-window(@list, $window) { (^(+@list - $window)).map: { @list[$_ ..^ $_+$window] } }
sub sliding-window(@list, $window) { (^(+@list - $window)).map: { @list[$_ .. $_+$window] } }


for flat (1e2, 1e3, 1e4, 1e5).map: { (1, 2.5, 5) »×» $_ } -> $upto {
for flat (1e2, 1e3, 1e4, 1e5).map: { (1, 2.5, 5) »×» $_ } -> $upto {
Line 499: Line 498:
my @sums = @primes.&sliding-window($_).grep: { .sum.is-prime }
my @sums = @primes.&sliding-window($_).grep: { .sum.is-prime }
next unless @sums;
next unless @sums;
say "\nFor primes up to {$upto.Int.&cardinal}:\nLongest sequence of consecutive primes yielding a prime sum: elements: {comma +$_}";
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}" }
for @sums { say " {join '...', .[0..5, *-5..*]».&comma».join(' + ')}, sum: {.sum.&comma}" }
last
last
Line 510: Line 509:


For primes up to two hundred fifty:
For primes up to two hundred fifty:
Longest sequence of consecutive primes yielding a prime sum: elements: 47
Longest sequence of consecutive primes yielding a prime sum: elements: 49
7 + 11 + 13 + 17 + 19 + 23...199 + 211 + 223 + 227 + 229, sum: 5,107
11 + 13 + 17 + 19 + 23 + 29...227 + 229 + 233 + 239 + 241, sum: 5,813
11 + 13 + 17 + 19 + 23 + 29...211 + 223 + 227 + 229 + 233, sum: 5,333


For primes up to five hundred:
For primes up to five hundred:
Longest sequence of consecutive primes yielding a prime sum: elements: 81
Longest sequence of consecutive primes yielding a prime sum: elements: 85
11 + 13 + 17 + 19 + 23 + 29...419 + 421 + 431 + 433 + 439, sum: 16,823
31 + 37 + 41 + 43 + 47 + 53...467 + 479 + 487 + 491 + 499, sum: 21,407
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:
For primes up to one thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 162
Longest sequence of consecutive primes yielding a prime sum: elements: 163
2 + 3 + 5 + 7 + 11 + 13...929 + 937 + 941 + 947 + 953, sum: 70,241
13 + 17 + 19 + 23 + 29 + 31...971 + 977 + 983 + 991 + 997, sum: 76,099


For primes up to two thousand, five hundred:
For primes up to two thousand, five hundred:
Line 538: Line 534:


For primes up to twenty-five thousand:
For primes up to twenty-five thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 2,757
Longest sequence of consecutive primes yielding a prime sum: elements: 2,759
3 + 5 + 7 + 11 + 13 + 17...24,919 + 24,923 + 24,943 + 24,953 + 24,967, sum: 32,305,799
7 + 11 + 13 + 17 + 19 + 23...24,967 + 24,971 + 24,977 + 24,979 + 24,989, sum: 32,405,707


For primes up to fifty thousand:
For primes up to fifty thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 5,125
Longest sequence of consecutive primes yielding a prime sum: elements: 5,131
13 + 17 + 19 + 23 + 29 + 31...49,927 + 49,937 + 49,939 + 49,943 + 49,957, sum: 120,863,297
5 + 7 + 11 + 13 + 17 + 19...49,943 + 49,957 + 49,991 + 49,993 + 49,999, sum: 121,013,303


For primes up to one hundred thousand:
For primes up to one hundred thousand:
Line 550: Line 546:


For primes up to two hundred fifty thousand:
For primes up to two hundred fifty thousand:
Longest sequence of consecutive primes yielding a prime sum: elements: 22,037
Longest sequence of consecutive primes yielding a prime sum: elements: 22,041
5 + 7 + 11 + 13 + 17 + 19...249,871 + 249,881 + 249,911 + 249,923 + 249,943, sum: 2,621,781,299
7 + 11 + 13 + 17 + 19 + 23...249,947 + 249,967 + 249,971 + 249,973 + 249,989, sum: 2,623,031,141


For primes up to five hundred thousand:
For primes up to five hundred thousand: