Ultra useful primes: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 275: | Line 275: | ||
<pre>1 3 5 15 5 59 159 189 569 105 |
<pre>1 3 5 15 5 59 159 189 569 105 |
||
1557 2549 2439</pre> |
1557 2549 2439</pre> |
||
=={{header|Ruby}}== |
|||
The 'prime?' method in Ruby's OpenSSL (standard) lib is much faster than the 'prime' lib. 0.05 sec. for this, about a minute for the next three. |
|||
<syntaxhighlight lang="ruby">require 'openssl' |
|||
(1..10).each do |n| |
|||
pow = 2 ** (2 ** n) |
|||
print "#{n}:\t" |
|||
puts (1..).step(2).detect{|k| OpenSSL::BN.new(pow-k).prime?} |
|||
end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>1: 1 |
|||
2: 3 |
|||
3: 5 |
|||
4: 15 |
|||
5: 5 |
|||
6: 59 |
|||
7: 159 |
|||
8: 189 |
|||
9: 569 |
|||
10: 105 |
|||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |