Repunit primes: Difference between revisions
Content added Content deleted
(→{{header|ALGOL 68}}: Added library) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 558: | Line 558: | ||
Base 35: 313 1297 |
Base 35: 313 1297 |
||
Base 36: 2</pre> |
Base 36: 2</pre> |
||
=={{header|Ruby}}== |
|||
Ruby's standard lib 'Prime' is boring slow for this. GMP to the rescue. GMP bindings is a gem, not in std lib. |
|||
<syntaxhighlight lang="ruby">require 'prime' |
|||
require 'gmp' |
|||
(2..16).each do |base| |
|||
res = Prime.each(1000).select {|n| GMP::Z(("1" * n).to_i(base)).probab_prime? > 0} |
|||
puts "Base #{base}: #{res.join(" ")}" |
|||
end |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Base 2: 2 3 5 7 13 17 19 31 61 89 107 127 521 607 |
|||
Base 3: 3 7 13 71 103 541 |
|||
Base 4: 2 |
|||
Base 5: 3 7 11 13 47 127 149 181 619 929 |
|||
Base 6: 2 3 7 29 71 127 271 509 |
|||
Base 7: 5 13 131 149 |
|||
Base 8: 3 |
|||
Base 9: |
|||
Base 10: 2 19 23 317 |
|||
Base 11: 17 19 73 139 907 |
|||
Base 12: 2 3 5 19 97 109 317 353 701 |
|||
Base 13: 5 7 137 283 883 991 |
|||
Base 14: 3 7 19 31 41 |
|||
Base 15: 3 43 73 487 |
|||
Base 16: 2 |
|||
</pre> |
|||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
{{works with|Chez Scheme}} |
{{works with|Chez Scheme}} |