CalmoSoft primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: Add a Raku example) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: generate test points programmatically, formatting) |
||
Line 198: | Line 198: | ||
Longest sliding window prime sums |
Longest sliding window prime sums |
||
<syntaxhighlight lang="raku" line> |
<syntaxhighlight lang="raku" line>use Lingua::EN::Numbers; |
||
sub sliding-window(@list, $window) { (^(+@list - $window)).map: { @list[$_ ..^ $_+$window] } } |
|||
for 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 -> $upto { |
|||
for flat (1e2, 1e3, 1e4, 1e5).map: { (1, 2.5, 5) »×» $_ } -> $upto { |
|||
my @primes = (^$upto).grep: &is-prime; |
my @primes = (^$upto).grep: &is-prime; |
||
Line 207: | Line 209: | ||
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 |
say "\nFor primes up to {$upto.Int.&cardinal}:\nLongest sequence of consecutive primes yielding a prime sum: elements: {comma +$_}"; |
||
for @sums { say " {join '...', .[0..5, *-5..*]».join('+')}, sum: {.sum}" } |
for @sums { say " {join '...', .[0..5, *-5..*]».&comma».join(' + ')}, sum: {.sum.&comma}" } |
||
last |
last |
||
} |
} |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>For primes up to |
<pre>For primes up to one hundred: |
||
⚫ | |||
7+11+13+17+19+23...71+73+79+83+89, sum: 953 |
7 + 11 + 13 + 17 + 19 + 23...71 + 73 + 79 + 83 + 89, sum: 953 |
||
For primes up to two hundred fifty: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
For primes up to five hundred: |
|||
⚫ | |||
11 + 13 + 17 + 19 + 23 + 29...419 + 421 + 431 + 433 + 439, sum: 16,823 |
|||
19 + 23 + 29 + 31 + 37 + 41...433 + 439 + 443 + 449 + 457, sum: 18,131 |
|||
⚫ | |||
For primes up to |
For primes up to one thousand: |
||
⚫ | |||
⚫ | |||
2 + 3 + 5 + 7 + 11 + 13...929 + 937 + 941 + 947 + 953, sum: 70,241 |
|||
For primes up to |
For primes up to two thousand, five hundred: |
||
Longest sequence of consecutive primes yielding a prime sum: elements: 359 |
|||
⚫ | |||
7 + 11 + 13 + 17 + 19 + 23...2,411 + 2,417 + 2,423 + 2,437 + 2,441, sum: 408,479 |
|||
⚫ | |||
For primes up to five thousand: |
|||
⚫ | |||
Longest sequence of consecutive primes yielding a prime sum: elements: 665 |
|||
2+3+5+7+11+13...929+937+941+947+953, sum: 70241 |
|||
7 + 11 + 13 + 17 + 19 + 23...4,967 + 4,969 + 4,973 + 4,987 + 4,993, sum: 1,543,127 |
|||
For primes up to ten thousand: |
|||
⚫ | |||
Longest sequence of consecutive primes yielding a prime sum: elements: 1,223 |
|||
7+11+13+17+19+23...2411+2417+2423+2437+2441, sum: 408479 |
|||
3 + 5 + 7 + 11 + 13 + 17...9,887 + 9,901 + 9,907 + 9,923 + 9,929, sum: 5,686,633 |
|||
7 + 11 + 13 + 17 + 19 + 23...9,907 + 9,923 + 9,929 + 9,931 + 9,941, sum: 5,706,497 |
|||
For primes up to twenty-five thousand: |
|||
⚫ | |||
Longest sequence of consecutive primes yielding a prime sum: elements: 2,757 |
|||
7+11+13+17+19+23...4967+4969+4973+4987+4993, sum: 1543127 |
|||
3 + 5 + 7 + 11 + 13 + 17...24,919 + 24,923 + 24,943 + 24,953 + 24,967, sum: 32,305,799 |
|||
For primes up to fifty thousand: |
|||
⚫ | |||
Longest sequence of consecutive primes yielding a prime sum: elements: 5,125 |
|||
3+5+7+11+13+17...9887+9901+9907+9923+9929, sum: 5686633 |
|||
13 + 17 + 19 + 23 + 29 + 31...49,927 + 49,937 + 49,939 + 49,943 + 49,957, sum: 120,863,297 |
|||
For primes up to |
For primes up to one hundred thousand: |
||
Longest sequence of consecutive primes yielding a prime sum: elements: 9,590 |
|||
3+5+7+11+13+17...24919+24923+24943+24953+24967, sum: 32305799 |
|||
2 + 3 + 5 + 7 + 11 + 13...99,907 + 99,923 + 99,929 + 99,961 + 99,971, sum: 454,196,557 |
|||
For primes up to |
For primes up to two hundred fifty thousand: |
||
Longest sequence of consecutive primes yielding a prime sum: elements: 22,037 |
|||
13+17+19+23+29+31...49927+49937+49939+49943+49957, sum: 120863297 |
|||
5 + 7 + 11 + 13 + 17 + 19...249,871 + 249,881 + 249,911 + 249,923 + 249,943, sum: 2,621,781,299 |
|||
For primes up to |
For primes up to five hundred thousand: |
||
Longest sequence of consecutive primes yielding a prime sum: elements: 41,530 |
|||
2+3+5+7+11+13...99907+99923+99929+99961+99971, sum: 454196557</pre> |
|||
2 + 3 + 5 + 7 + 11 + 13...499,801 + 499,819 + 499,853 + 499,879 + 499,883, sum: 9,910,236,647</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |