CalmoSoft primes: Difference between revisions
Content added Content deleted
(Algol 68 stretch - corrected comment) |
Thundergnat (talk | contribs) 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[$_ .. |
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: |
Longest sequence of consecutive primes yielding a prime sum: elements: 49 |
||
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: |
Longest sequence of consecutive primes yielding a prime sum: elements: 85 |
||
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: |
Longest sequence of consecutive primes yielding a prime sum: elements: 163 |
||
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, |
Longest sequence of consecutive primes yielding a prime sum: elements: 2,759 |
||
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, |
Longest sequence of consecutive primes yielding a prime sum: elements: 5,131 |
||
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, |
Longest sequence of consecutive primes yielding a prime sum: elements: 22,041 |
||
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: |