Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: minor optimizations) |
(→{{header|Wren}}: Stretched to primes under 1 billion.) |
||
Line 940: | Line 940: | ||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
<lang ecmascript>import "/math" for Int |
<lang ecmascript>import "./math" for Int |
||
import "/fmt" for Fmt |
import "./fmt" for Fmt |
||
import "/seq" for Lst |
import "./seq" for Lst |
||
var limit = 999 |
var limit = 999 |
||
var maxDigits = 3 |
var maxDigits = 3 |
||
Line 953: | Line 953: | ||
Fmt.print("Primes under $,d which contain only one odd digit:", limit + 1) |
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) |
for (chunk in Lst.chunks(results, 9)) Fmt.print("$,%(maxDigits)d", chunk) |
||
System.print("\nFound %(results.count) such primes.") |
System.print("\nFound %(results.count) such primes.\n") |
||
limit = |
limit = 1e9 - 1 |
||
primes = Int.primeSieve(limit) |
primes = Int.primeSieve(limit) |
||
var count = 0 |
var count = 0 |
||
var pow = 10 |
|||
for (prime in primes.skip(1)) { |
for (prime in primes.skip(1)) { |
||
if (Int.digits(prime)[0...-1].all { |d| d & 1 == 0 }) count = count + 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(" |
Fmt.print("There are $,7d such primes under $,d", count, pow)</lang> |
||
{{out}} |
{{out}} |
||
Line 974: | Line 979: | ||
Found 45 such primes. |
Found 45 such primes. |
||
There are |
There are 3 such primes under 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> |
</pre> |
||