Primes which contain only one odd digit: Difference between revisions
Primes which contain only one odd digit (view source)
Revision as of 09:22, 10 April 2022
, 2 years ago→{{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 =
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("
{{out}}
Line 974 ⟶ 979:
Found 45 such primes.
There are
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>
|