Jump to content

Wagstaff primes: Difference between revisions

(→‎OCaml: much faster without prime generator)
Line 549:
29: 14479 (179.87)
^C</pre>
 
=={{header|Ruby}}==
For the first 12 the Ruby prime library is sufficiently fast. Here, the external GMP gem is used in order to do more.
<syntaxhighlight lang="ruby">require 'prime'
require 'gmp'
 
wagstaffs = Enumerator.new do |y|
odd_primes = Prime.each
odd_primes.next #skip 2
loop do
p = odd_primes.next
candidate = (2 ** p + 1)/3
y << [p, candidate] unless GMP::Z.new(candidate).probab_prime?.zero?
end
end
 
10.times{puts "%5d - %s" % wagstaffs.next}
14.times{puts "%5d" % wagstaffs.next.first}
</syntaxhighlight>
{{out}}
<pre> 3 - 3
5 - 11
7 - 43
11 - 683
13 - 2731
17 - 43691
19 - 174763
23 - 2796203
31 - 715827883
43 - 2932031007403
61
79
101
127
167
191
199
313
347
701
1709
2617
3539
5807
</pre>
 
=={{header|Wren}}==
1,149

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.