Primes which contain only one odd digit: Difference between revisions

Content added Content deleted
(→‎{{header|Wren}}: Stretched to primes under 1 billion.)
(→‎{{header|Go}}: Stretched to primes under 10 billion.)
Line 377: Line 377:
const (
const (
LIMIT = 999
LIMIT = 999
LIMIT2 = 999999
LIMIT2 = 9999999999
MAX_DIGITS = 3
MAX_DIGITS = 3
)
)
Line 394: Line 394:
}
}
}
}
fmt.Println("\nFound", len(results), "such primes.")
fmt.Println("\nFound", len(results), "such primes.\n")


primes = rcu.Primes(LIMIT2)
primes = rcu.Primes(LIMIT2)
count := 0
count := 0
pow := 10
for _, prime := range primes[1:] {
for _, prime := range primes[1:] {
if allButOneEven(prime) {
if allButOneEven(prime) {
count = count + 1
count++
}
if prime > pow {
fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
pow *= 10
}
}
}
}
cs := rcu.Commatize(count)
fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
ls := rcu.Commatize(LIMIT2 + 1)
fmt.Println("\nThere are", cs, "primes under", ls, "which contain only one odd digit.")
}</lang>
}</lang>


Line 419: Line 422:
Found 45 such primes.
Found 45 such primes.


There are 2,560 primes under 1,000,000 which contain only one odd digit.
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
There are 904,603 such primes under 10,000,000,000
</pre>
</pre>