Jump to content

CalmoSoft primes: Difference between revisions

m
→‎{{header|Raku}}: generate test points programmatically, formatting
m (→‎{{header|Raku}}: Add a Raku example)
m (→‎{{header|Raku}}: generate test points programmatically, formatting)
Line 198:
Longest sliding window prime sums
 
<syntaxhighlight lang="raku" line>subuse sliding-window(@list, $window) { (^(+@list - $window)).mapLingua: { @list[$_ ..^ $_+$window] } }: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;
Line 207 ⟶ 209:
my @sums = @primes.&sliding-window($_).grep: { .sum.is-prime }
next unless @sums;
say "\nFor primes up to {$upto, longest.Int.&cardinal}:\nLongest sequence of consecutive primes yielding a prime sum: elements: {comma +$_}";
for @sums { say " {join '...', .[0..5, *-5..*]».&comma».join(' + ')}, sum: {.sum.&comma}" }
last
}
}</syntaxhighlight>
{{out}}
<pre>For primes up to 100,one longest sequence of consecutive primes yielding a prime sumhundred: elements 21
For primes up to 1000, longestLongest sequence of consecutive primes yielding a prime sum: elements: 16221
7 + 11 + 13 + 17 + 19 + 23...71 + 73 + 79 + 83 + 89, sum: 953
 
For primes up to two hundred fifty:
For primes up to 2500, longestLongest sequence of consecutive primes yielding a prime sum: elements: 35947
7 + 11 + 13 + 17 + 19 + 23...199 + 211 + 223 + 227 + 229, sum: 51075,107
11 + 13 + 17 + 19 + 23 + 29...419211 +421 223 +431 227 +433 229 +439 233, sum: 168235,333
 
For primes up to five hundred:
For primes up to 5000, longestLongest sequence of consecutive primes yielding a prime sum: elements: 66581
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
29 + 31 + 37 + 41 + 43 + 47...443 + 449 + 457 + 461 + 463, sum: 1901319,013
 
For primes up to 250,one longest sequence of consecutive primes yielding a prime sumthousand: elements 47
For primes up to 10000, longestLongest sequence of consecutive primes yielding a prime sum: elements: 1223162
7+11+13+17+19+23...199+211+223+227+229, sum: 5107
112 +13 3 +17 5 +19 7 +23 11 +29 13...211929 +223 937 +227 941 +229 947 +233 953, sum: 533370,241
 
For primes up to 500two thousand, longestfive sequence of consecutive primes yielding a prime sumhundred: elements 81
Longest sequence of consecutive primes yielding a prime sum: elements: 359
11+13+17+19+23+29...419+421+431+433+439, sum: 16823
197 +23 11 +29 13 +31 17 +37 19 +41 23...4332,411 +439 2,417 +443 2,423 +449 2,437 +457 2,441, sum: 18131408,479
29+31+37+41+43+47...443+449+457+461+463, sum: 19013
 
For primes up to five thousand:
For primes up to 1000, longest sequence of consecutive primes yielding a prime sum: elements 162
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:
For primes up to 2500, longest sequence of consecutive primes yielding a prime sum: elements 359
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:
For primes up to 5000, longest sequence of consecutive primes yielding a prime sum: elements 665
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:
For primes up to 10000, longest sequence of consecutive primes yielding a prime sum: elements 1223
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
7+11+13 + 17 + 19 + 23 + 29 + 31...990749,927 +9923 49,937 +9929 49,939 +9931 49,943 +9941 49,957, sum: 5706497120,863,297
 
For primes up to 25000,one longesthundred sequence of consecutive primes yielding a prime sumthousand: elements 2757
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 50000,two longesthundred sequencefifty of consecutive primes yielding a prime sumthousand: elements 5125
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 100000,five longesthundred sequence of consecutive primes yielding a prime sumthousand: elements 9590
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}}==
10,343

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.