Consecutive primes with ascending or descending differences: Difference between revisions
Consecutive primes with ascending or descending differences (view source)
Revision as of 18:48, 21 October 2021
, 2 years ago→{{header|Ruby}}: Add Ruby
m (→{{header|Pari/GP}}: clarify) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 944:
8 was the longest run of consecutive primes whose differences between primes are strictly descending and < 1,000,000
</pre>
=={{header|Ruby}}==
<lang ruby>require "prime"
limit = 1_000_000
puts "First fount longest run of ascending prime gaps up to #{limit}:"
p Prime.each(limit).each_cons(2).chunk_while{|(i1,i2), (j1,j2)| j1-i1 < j2-i2 }.max_by(&:size).flatten.uniq
puts "\nFirst fount longest run of descending prime gaps up to #{limit}:"
p Prime.each(limit).each_cons(2).chunk_while{|(i1,i2), (j1,j2)| j1-i1 > j2-i2 }.max_by(&:size).flatten.uniq</lang>
{{out}}
<pre>First fount longest run of ascending prime gaps up to 1000000:
[128981, 128983, 128987, 128993, 129001, 129011, 129023, 129037]
First fount longest run of descending prime gaps up to 1000000:
[322171, 322193, 322213, 322229, 322237, 322243, 322247, 322249]
</pre>
|