Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
(Added Sidef) |
m (→{{header|Sidef}}: minor optimizations and simplifications) |
||
Line 367:
=={{header|Sidef}}==
<lang ruby>func primes_with_one_odd_digit(upto, base = 10) {
var digits = @(^base)
break if ([1,
odd_digits.each
var
}
})
}
list.sort
}
with (1e3) {|n|
var list = primes_with_one_odd_digit(1000)
say "There are #{list.len} primes under #{n.commify} which contain only one odd digit:"
list.each_slice(9, {|*a| say a.map { '%3s' % _ }.join(' ') })
Line 395 ⟶ 397:
for k in (1..8) {
var count = primes_with_one_odd_digit(10**k)
say "There are #{'%6s' % count.commify} such primes <= 10^#{k}"
}</lang>
|