Consecutive primes with ascending or descending differences: Difference between revisions

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>
 
1,149

edits