Find adjacent primes which differ by a square integer: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example. Sig. I guess we're going to get 30 trivial variations on prime gap tasks now...) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Change to be not so trivial) |
||
Line 211: | Line 211: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang perl6>use |
<lang perl6>use Lingua::EN::Numbers; |
||
use Math::Primesieve; |
|||
my $iterator = Math::Primesieve::iterator.new; |
my $iterator = Math::Primesieve::iterator.new; |
||
my $limit = |
my $limit = 1e8; |
||
my @squares = ( |
my @squares = (1..100).map: *²; |
||
my $last = 2; |
my $last = 2; |
||
my @gaps; |
my @gaps; |
||
Line 226: | Line 227: | ||
} |
} |
||
print "Adjacent primes up to {comma $limit.Int} with a gap value that is a perfect square:"; |
|||
for @gaps.pairs.grep: { (.key ∈ @squares) && .value.defined |
for @gaps.pairs.grep: { (.key ∈ @squares) && .value.defined} -> $p { |
||
⚫ | |||
my $ten = ($p.value > 10) ?? ', (first ten)' !! ''; |
|||
⚫ | |||
put join "\n", $p.value.head(10).batch(5)».map({"($_, {$_+ $p.key})"})».join(', '); |
|||
}</lang> |
}</lang> |
||
{{out}} |
{{out}} |
||
<pre>Adjacent primes up to 100,000,000 with a gap value that is a perfect square: |
|||
<pre>Gap 64: |
|||
Gap 1: 1 found: |
|||
⚫ | |||
(2, 3) |
|||
⚫ | |||
(625699, 625763), (637003, 637067), (710713, 710777), (725209, 725273) |
|||
(779413, 779477), (801883, 801947), (803749, 803813), (821677, 821741) |
|||
(832519, 832583), (844777, 844841), (883807, 883871), (912103, 912167) |
|||
(919447, 919511), (954763, 954827), (981823, 981887), (997813, 997877) |
|||
Gap 4: 440,257 found, (first ten): |
|||
Gap 100: |
|||
(7, 11), (13, 17), (19, 23), (37, 41), (43, 47) |
|||
(396733, 396833), (838249, 838349) |
|||
(67, 71), (79, 83), (97, 101), (103, 107), (109, 113) |
|||
</pre> |
|||
Gap 16: 215,804 found, (first ten): |
|||
(1831, 1847), (1933, 1949), (2113, 2129), (2221, 2237), (2251, 2267) |
|||
(2593, 2609), (2803, 2819), (3121, 3137), (3373, 3389), (3391, 3407) |
|||
Gap 36: 114,028 found, (first ten): |
|||
(9551, 9587), (12853, 12889), (14107, 14143), (15823, 15859), (18803, 18839) |
|||
(22193, 22229), (22307, 22343), (22817, 22853), (24281, 24317), (27143, 27179) |
|||
Gap 64: 8,823 found, (first ten): |
|||
⚫ | |||
⚫ | |||
Gap 100: 878 found, (first ten): |
|||
(396733, 396833), (838249, 838349), (1313467, 1313567), (1648081, 1648181), (1655707, 1655807) |
|||
(2345989, 2346089), (2784373, 2784473), (3254959, 3255059), (3595489, 3595589), (4047157, 4047257) |
|||
Gap 144: 51 found, (first ten): |
|||
(11981443, 11981587), (18687587, 18687731), (20024339, 20024483), (20388583, 20388727), (21782503, 21782647) |
|||
(25507423, 25507567), (27010003, 27010147), (28716287, 28716431), (31515413, 31515557), (32817493, 32817637) |
|||
Gap 196: 1 found: |
|||
(70396393, 70396589)</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |