De Polignac numbers: Difference between revisions

(→‎{{header|Nim}}: append {{header|Pascal}} trans Delphi)
Line 1,309:
<pre>
1: { 1 127 149 251 331 337 373 509 599 701 757 809 877 905 907 959 977 997 1019 1087 1199 1207 1211 1243 1259 1271 1477 1529 1541 1549 1589 1597 1619 1649 1657 1719 1759 1777 1783 1807 1829 1859 1867 1927 1969 1973 1985 2171 2203 }
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'prime'
 
def pow2floor(n)
n.digits(2).size-1
end
 
def polignac?(n)
(0..pow2floor(n)).none? {|exp| (n-(1 << exp)).prime? }
end
 
polignacs = (1..).step(2).lazy.select{|n| polignac?(n)}.first(10000)
 
puts "first #{n = 50} de Polignac numbers:"
polignacs[0...n].each_slice(10){|s| puts "%5d"*s.size % s}
[1000, 10000].each{|n| puts "\n#{n}: #{polignacs[n-1]}"}
</syntaxhighlight>
{{out}}
<pre>first 50 de Polignac numbers:
1 127 149 251 331 337 373 509 599 701
757 809 877 905 907 959 977 997 1019 1087
1199 1207 1211 1243 1259 1271 1477 1529 1541 1549
1589 1597 1619 1649 1657 1719 1759 1777 1783 1807
1829 1859 1867 1927 1969 1973 1985 2171 2203 2213
 
1000: 31941
 
10000: 273421
</pre>
 
1,149

edits