Pierpont primes: Difference between revisions

Content added Content deleted
(→‎{{header|Perl 6}}: Add a generalized Pierpont number generator version)
Line 362: Line 362:
=={{header|Perl 6}}==
=={{header|Perl 6}}==
{{works with|Rakudo|2019.07.1}}
{{works with|Rakudo|2019.07.1}}
==Finesse version==


This finesse version never produces more Pierpont numbers than it needs to
This finesse version never produces more Pierpont numbers than it needs to
Line 402: Line 403:
say "\n250th Pierpont prime of the first kind: " ~ pierpont[249];
say "\n250th Pierpont prime of the first kind: " ~ pierpont[249];


say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249];
say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249];</lang>


# And the question absolutely nobody was asking:

say "\n1000th Pierpont prime of the first kind:\n" ~ pierpont[999];

say "\n1000th Pierpont prime of the second kind:\n" ~ pierpont(2)[999];</lang>
{{out}}
{{out}}
<pre>First 50 Pierpont primes of the first kind:
<pre>First 50 Pierpont primes of the first kind:
Line 426: Line 422:
250th Pierpont prime of the first kind: 62518864539857068333550694039553
250th Pierpont prime of the first kind: 62518864539857068333550694039553


250th Pierpont prime of the second kind: 4111131172000956525894875083702271
250th Pierpont prime of the second kind: 4111131172000956525894875083702271</pre>

==Generalized Pierpont iterator==
Alternately, a version that will generate [[wp:Pierpont_prime#Generalization|generalized Pierpont numbers]] for any set of prime integers where at least one of the primes is 2.

(Cut down output as it is exactly the same as the first version for {2,3} +1 and {2,3} -1; leaves room to demo some other options.)

<lang perl6>sub smooth-numbers (*@list) {
cache my \Smooth := gather {
my %i = (flat @list) Z=> (Smooth.iterator for ^@list);
my %n = (flat @list) Z=> 1 xx *;

loop {
take my $n := %n{*}.min;

for @list -> \k {
%n{k} = %i{k}.pull-one * k if %n{k} == $n;
}
}
}
}

# Testing various smooth numbers

for 'OEIS: A092506 - Fermat primes:', (2), 1, 6,
"\nOEIS: A000668 - Mersenne primes:", (2), -1, 10,
"\nOEIS: A005109 - Pierpont primes 1st:", (2,3), 1, 20,
"\nOEIS: A005105 - Pierpont primes 2nd:", (2,3), -1, 20,
"\nOEIS: A077497:", (2,5), 1, 20,
"\nOEIS:A077313:", (2,5), -1, 20,
"\nOEIS: A002200 - (\"Hamming\" primes 1st):", (2,3,5), 1, 20,
"\nOEIS:A293194 - (\"Hamming\" primes 2nd):", (2,3,5), -1, 20,
"\nOEIS: A077498:", (2,7), 1, 20,
"\nOEIS:A077314:", (2,7), -1, 20,
"\nOEIS: A174144 - (\"Humble\" primes 1st):", (2,3,5,7), 1, 20,
"\n(\"Humble\" primes 2nd):", (2,3,5,7), -1, 20,
"\nOEIS: A077499:", (2,11), 1, 20,
"\nOEIS:A077315:", (2,11), -1, 20,
"\nOEIS: A173236:", (2,13), 1, 20,
"\nOEIS:A173062:", (2,13), -1, 20

-> $title, $primes, $add, $count {

say "$title smooth \{$primes\} {$add > 0 ?? '+' !! '-'} 1 ";
put smooth-numbers(|$primes).map( * + $add ).grep( *.is-prime )[^$count]
}</lang>

{{Out}}
<pre>OEIS: A092506 - Fermat primes: smooth {2} + 1
2 3 5 17 257 65537

OEIS: A000668 - Mersenne primes: smooth {2} - 1
3 7 31 127 8191 131071 524287 2147483647 2305843009213693951 618970019642690137449562111

OEIS: A005109 - Pierpont primes 1st: smooth {2 3} + 1
2 3 5 7 13 17 19 37 73 97 109 163 193 257 433 487 577 769 1153 1297

OEIS: A005105 - Pierpont primes 2nd: smooth {2 3} - 1
2 3 5 7 11 17 23 31 47 53 71 107 127 191 383 431 647 863 971 1151

OEIS: A077497: smooth {2 5} + 1
2 3 5 11 17 41 101 251 257 401 641 1601 4001 16001 25601 40961 62501 65537 160001 163841

OEIS:A077313: smooth {2 5} - 1
3 7 19 31 79 127 199 499 1249 1279 1999 4999 5119 8191 12799 20479 31249 49999 51199 79999

OEIS: A002200 - ("Hamming" primes 1st): smooth {2 3 5} + 1
2 3 5 7 11 13 17 19 31 37 41 61 73 97 101 109 151 163 181 193

OEIS:A293194 - ("Hamming" primes 2nd): smooth {2 3 5} - 1
2 3 5 7 11 17 19 23 29 31 47 53 59 71 79 89 107 127 149 179

OEIS: A077498: smooth {2 7} + 1
2 3 5 17 29 113 197 257 449 1373 3137 50177 65537 114689 268913 470597 614657 1075649 3294173 7340033

OEIS:A077314: smooth {2 7} - 1
3 7 13 31 97 127 223 1567 3583 4801 6271 8191 19207 25087 33613 76831 131071 401407 524287 917503

OEIS: A174144 - ("Humble" primes 1st): smooth {2 3 5 7} + 1
2 3 5 7 11 13 17 19 29 31 37 41 43 61 71 73 97 101 109 113

("Humble" primes 2nd): smooth {2 3 5 7} - 1
2 3 5 7 11 13 17 19 23 29 31 41 47 53 59 71 79 83 89 97

OEIS: A077499: smooth {2 11} + 1
2 3 5 17 23 89 257 353 1409 2663 30977 65537 170369 495617 5767169 23068673 59969537 82458113 453519617 3429742097

OEIS:A077315: smooth {2 11} - 1
3 7 31 43 127 241 967 5323 8191 117127 131071 524287 7496191 10307263 77948683 253755391 428717761 738197503 1714871047 2147483647


OEIS: A173236: smooth {2 13} + 1
1000th Pierpont prime of the first kind:
2 3 5 17 53 257 677 3329 13313 35153 65537 2768897 13631489 2303721473 3489660929 4942652417 11341398017 10859007357953 1594691292233729 31403151600910337
69269314716439690250482558089997110961545818230232043107188537422260188701607997086273960899938499201024414931399264696270849


OEIS:A173062: smooth {2 13} - 1
1000th Pierpont prime of the second kind:
3 7 31 103 127 337 1663 5407 8191 131071 346111 524287 2970343 3655807 22151167 109051903 617831551 1631461441 2007952543 2147483647</pre>
1308088756227965581249669045506775407896673213729433892383353027814827286537163695213418982500477392209371001259166465228280492460735463423</pre>


=={{header|REXX}}==
=={{header|REXX}}==