Primes which contain only one odd digit: Difference between revisions
Primes which contain only one odd digit (view source)
Revision as of 14:44, 28 July 2021
, 2 years ago→{{header|Go}}: Added stretch goal.
m (added "only".) |
(→{{header|Go}}: Added stretch goal.) |
||
Line 28:
"rcu"
)
func allButOneEven(prime int) bool {
digits := rcu.Digits(prime, 10)
}▼
}
}
func main() {
const (
LIMIT = 999
MAX_DIGITS = 3
)
Line 37 ⟶ 51:
var results []int
for _, prime := range primes[1:] {
▲ digits = digits[:len(digits)-1]
▲ allEven := true
▲ for _, d := range digits {
▲ if d&1 == 1 {
▲ allEven = false
▲ break
▲ }
▲ }
▲ if allEven {
results = append(results, prime)
}
Line 58 ⟶ 63:
}
fmt.Println("\nFound", len(results), "such primes.")
primes = rcu.Primes(LIMIT2)
count := 0
for _, prime := range primes[1:] {
if allButOneEven(prime) {
count = count + 1
}
}
cs := rcu.Commatize(count)
ls := rcu.Commatize(LIMIT2 + 1)
fmt.Println("\nThere are", cs, "primes under", ls, "which contain only one odd digit.")
}</lang>
Line 70 ⟶ 86:
Found 45 such primes.
There are 2,560 primes under 1,000,000 which contain only one odd digit.
</pre>
|