Primes which contain only one odd digit: Difference between revisions

→‎{{header|Wren}}: Stretched to primes under 1 billion.
m (→‎{{header|Sidef}}: minor optimizations)
(→‎{{header|Wren}}: Stretched to primes under 1 billion.)
Line 940:
{{libheader|Wren-fmt}}
{{libheader|Wren-seq}}
<lang ecmascript>import "./math" for Int
import "./fmt" for Fmt
import "./seq" for Lst
 
var limit = 999
var maxDigits = 3
Line 953:
Fmt.print("Primes under $,d which contain only one odd digit:", limit + 1)
for (chunk in Lst.chunks(results, 9)) Fmt.print("$,%(maxDigits)d", chunk)
System.print("\nFound %(results.count) such primes.\n")
 
limit = 9999991e9 - 1
primes = Int.primeSieve(limit)
var count = 0
var pow = 10
for (prime in primes.skip(1)) {
if (Int.digits(prime)[0...-1].all { |d| d & 1 == 0 }) count = count + 1
if (prime > pow) {
Fmt.print("There are $,7d such primes under $,d", count, pow)
pow = pow * 10
}
}
Fmt.print("\nThereThere are $,d7d such primes under $,d which contain only one odd digit.", count, limit + 1pow)</lang>
 
{{out}}
Line 974 ⟶ 979:
Found 45 such primes.
 
There are 2,560 primes under 1,000,000 which contain only3 onesuch oddprimes under digit.10
There are 12 such primes under 100
There are 45 such primes under 1,000
There are 171 such primes under 10,000
There are 619 such primes under 100,000
There are 2,560 such primes under 1,000,000
There are 10,774 such primes under 10,000,000
There are 46,708 such primes under 100,000,000
There are 202,635 such primes under 1,000,000,000
</pre>
 
9,482

edits