Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
m (added "only".) |
(→{{header|Go}}: Added stretch goal.) |
||
Line 28: | Line 28: | ||
"rcu" |
"rcu" |
||
) |
) |
||
func allButOneEven(prime int) bool { |
|||
digits := rcu.Digits(prime, 10) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
} |
|||
func main() { |
func main() { |
||
const ( |
const ( |
||
LIMIT = 999 |
LIMIT = 999 |
||
⚫ | |||
MAX_DIGITS = 3 |
MAX_DIGITS = 3 |
||
) |
) |
||
Line 37: | Line 51: | ||
var results []int |
var results []int |
||
for _, prime := range primes[1:] { |
for _, prime := range primes[1:] { |
||
if allButOneEven(prime) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
results = append(results, prime) |
results = append(results, prime) |
||
} |
} |
||
Line 58: | Line 63: | ||
} |
} |
||
fmt.Println("\nFound", len(results), "such primes.") |
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> |
}</lang> |
||
Line 70: | Line 86: | ||
Found 45 such primes. |
Found 45 such primes. |
||
There are 2,560 primes under 1,000,000 which contain only one odd digit. |
|||
</pre> |
</pre> |
||