Twin primes: Difference between revisions
Content added Content deleted
(Added C#) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 1,327: | Line 1,327: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
<lang ruby>require 'prime' |
|||
(1..8).each do |n| |
|||
count = Prime.each(10**n).each_cons(2).count{|p1, p2| p2-p1 == 2} |
|||
puts "Twin primes below 10**#{n}: #{count}" |
|||
end |
|||
</lang> |
|||
{{out}} |
|||
<pre>Twin primes below 10**1: 2 |
|||
Twin primes below 10**2: 8 |
|||
Twin primes below 10**3: 35 |
|||
Twin primes below 10**4: 205 |
|||
Twin primes below 10**5: 1224 |
|||
Twin primes below 10**6: 8169 |
|||
Twin primes below 10**7: 58980 |
|||
Twin primes below 10**8: 440312 |
|||
</pre> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Limits can be specified on the command line, otherwise the twin prime counts for powers |
Limits can be specified on the command line, otherwise the twin prime counts for powers |