Cullen and Woodall numbers: Difference between revisions

(Added XPL0 example.)
Line 759:
</pre>
 
=={{header|Ruby}}==
The OpenSSL prime? methods is faster than the standard one. It still takes 1-2 minutes to calculate the first 5 Cullen primes.
<syntaxhighlight lang="ruby">require 'openssl'
 
cullen = Enumerator.new{|y| (1..).each{|n| y << (n*(1<<n) + 1)} }
woodall = Enumerator.new{|y| (1..).each{|n| y << (n*(1<<n) - 1)} }
cullen_primes = Enumerator.new{|y| (1..).each {|i|y << i if OpenSSL::BN.new(cullen.next).prime?}}
woodall_primes = Enumerator.new{|y| (1..).each{|i|y << i if OpenSSL::BN.new(woodall.next).prime?}}
 
num = 20
puts "First #{num} Cullen numbers:\n#{cullen.first(num).join(" ")}"
puts "First #{num} Woodal numbers:\n#{woodall.first(num).join(" ")}"
puts "First 5 Cullen primes:\n#{cullen_primes.first(5).join(", ")}"
puts "First 12 Woodall primes:\n#{woodall_primes.first(12).join(", ")}"
</syntaxhighlight>
{{out}}
<pre>First 20 Cullen numbers:
3 9 25 65 161 385 897 2049 4609 10241 22529 49153 106497 229377 491521 1048577 2228225 4718593 9961473 20971521
First 20 Woodal numbers:
1 7 23 63 159 383 895 2047 4607 10239 22527 49151 106495 229375 491519 1048575 2228223 4718591 9961471 20971519
First 5 Cullen primes:
1, 141, 4713, 5795, 6611
First 12 Woodall primes:
2, 3, 6, 30, 75, 81, 115, 123, 249, 362, 384, 462
</pre>
=={{header|Rust}}==
<syntaxhighlight lang="rust">// [dependencies]
1,149

edits