Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
(add RPL) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 1,038: | Line 1,038: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
<syntaxhighlight lang="ruby">require 'prime' |
|||
def single_odd?(pr) |
|||
d = pr.digits |
|||
d.first.odd? && d[1..].all?(&:even?) |
|||
end |
|||
res = Prime.each(1000).select {|pr| single_odd?(pr)} |
|||
res.each_slice(10){|s| puts "%4d"*s.size % s} |
|||
n = 1_000_000 |
|||
count = Prime.each(n).count{|pr| single_odd?(pr)} |
|||
puts "\nFound #{count} single-odd-digit primes upto #{n}." |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 3 5 7 23 29 41 43 47 61 67 |
|||
83 89 223 227 229 241 263 269 281 283 |
|||
401 409 421 443 449 461 463 467 487 601 |
|||
607 641 643 647 661 683 809 821 823 827 |
|||
829 863 881 883 887 |
|||
Found 2560 single-odd-digit primes upto 1000000. |
|||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">func primes_with_one_odd_digit(upto, base = 10) { |
<syntaxhighlight lang="ruby">func primes_with_one_odd_digit(upto, base = 10) { |