Penta-power prime seeds: Difference between revisions

From Rosetta Code
Content added Content deleted
m (Thundergnat moved page Quad-power plus prime seeds to Penta-power prime seeds: Better name IMO)
(Change descriptions to match task rename)
Line 1: Line 1:
{{draft task}}
{{draft task}}


Generate the sequence of quad-power prime seeds: positive integers '''n''' such that:
Generate the sequence of penta-power prime seeds: positive integers '''n''' such that:


<big>'''n<sup>0</sup> + n + 1, n<sup>1</sup> + n + 1, n<sup>2</sup> + n + 1, n<sup>3</sup> + n + 1''' and '''n<sup>4</sup> + n + 1''' are all prime.</big>
<big>'''n<sup>0</sup> + n + 1, n<sup>1</sup> + n + 1, n<sup>2</sup> + n + 1, n<sup>3</sup> + n + 1''' and '''n<sup>4</sup> + n + 1''' are all prime.</big>
Line 7: Line 7:


;Task
;Task
* Find and display the first thirty quad-power plus prime seeds.
* Find and display the first thirty penta-power prime seeds.




Line 23: Line 23:
<lang perl6>use Lingua::EN::Numbers;
<lang perl6>use Lingua::EN::Numbers;


my @qppps = lazy (1..*).hyper(:2000batch).grep: -> \n { my \k = n + 1; (1+k).is-prime && (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime }
my @ppps = lazy (1..*).hyper(:2000batch).grep: -> \n { my \k = n + 1; (1+k).is-prime && (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime }


say "First thirty quad-power plus prime seeds:\n" ~ @qppps[^30].batch(10)».&comma».fmt("%9s").join: "\n";
say "First thirty penta-power prime seeds:\n" ~ @ppps[^30].batch(10)».&comma».fmt("%9s").join: "\n";


say "\nFirst quad-power plus prime seed greater than:";
say "\nFirst penta-power prime seed greater than:";


for 1..10 {
for 1..10 {
my $threshold = Int(1e6 * $_);
my $threshold = Int(1e6 * $_);
my $key = @qppps.first: * > $threshold, :k;
my $key = @ppps.first: * > $threshold, :k;
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@qppps[$key].&comma}";
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@ppps[$key].&comma}";
}</lang>
}</lang>
{{out}}
{{out}}
<pre>First thirty quad-power plus prime seeds:
<pre>First thirty penta-power prime seeds:
1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535
1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535
82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859
82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859
644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321
644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321


First quad-power plus prime seed greater than:
First penta-power prime seed greater than:
one million is the 26th: 1,121,189
one million is the 26th: 1,121,189
two million is the 39th: 2,066,079
two million is the 39th: 2,066,079

Revision as of 21:31, 19 August 2022

Penta-power prime seeds is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Generate the sequence of penta-power prime seeds: positive integers n such that:

   n0 + n + 1, n1 + n + 1, n2 + n + 1, n3 + n + 1 and n4 + n + 1 are all prime.


Task
  • Find and display the first thirty penta-power prime seeds.


Stretch
  • Find and display the position and value of first with a value greater than ten million.


See also

I can find no mention or record of this sequence anywhere. Perhaps I've invented it.



Raku

<lang perl6>use Lingua::EN::Numbers;

my @ppps = lazy (1..*).hyper(:2000batch).grep: -> \n { my \k = n + 1; (1+k).is-prime && (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime }

say "First thirty penta-power prime seeds:\n" ~ @ppps[^30].batch(10)».&comma».fmt("%9s").join: "\n";

say "\nFirst penta-power prime seed greater than:";

for 1..10 {

   my $threshold = Int(1e6 * $_);
   my $key = @ppps.first: * > $threshold, :k;
   say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@ppps[$key].&comma}";

}</lang>

Output:
First thirty penta-power prime seeds:
        1         5        69     1,665     2,129    25,739    29,631    62,321    77,685    80,535
   82,655   126,489   207,285   211,091   234,359   256,719   366,675   407,945   414,099   628,859
  644,399   770,531   781,109   782,781   923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321

First penta-power prime seed greater than:
  one million is the 26th: 1,121,189
  two million is the 39th: 2,066,079
three million is the 47th: 3,127,011
 four million is the 51st: 4,059,525
 five million is the 59th: 5,279,175
  six million is the 63rd: 6,320,601
seven million is the 68th: 7,291,361
eight million is the 69th: 8,334,915
 nine million is the 71st: 9,100,671
  ten million is the 72nd: 10,347,035