Primes which contain only one odd digit
Primes which contain only one odd digit is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
- Primes which contain only one odd number, where n < 1,000
Julia
If only one digit of a prime is odd, then that odd digit is the ones place digit. <lang julia>using Primes
function isoneoddprime(n, base = 10)
d = digits(n, base = base) return isodd(first(d)) && all(iseven, d[begin+1:end])
end
found = filter(isoneoddprime, primes(1000)) println("Found $(length(found)) primes with one odd digit in base 10:") foreach(p -> print(rpad(last(p), 5), first(p) % 9 == 0 ? "\n" : ""), enumerate(found))
</lang>
- Output:
Found 45 primes with one odd digit in base 10: 3 5 7 23 29 41 43 47 61 67 83 89 223 227 229 241 263 269 281 283 401 409 421 443 449 461 463 467 487 601 607 641 643 647 661 683 809 821 823 827 829 863 881 883 887
Ring
<lang ring> load "stdlib.ring" see "working..." + nl see "Primes which contain only one odd number:" + nl row = 0
for n = 1 to 1000
odd = 0 str = string(n) for m = 1 to len(str) if number(str[m])%2 = 1 odd++ ok next if odd = 1 and isprime(n) see "" + n + " " row++ if row%5 = 0 see nl ok ok
next
see "Found " + row + " prime numbers" + nl see "done..." + nl </lang>
- Output:
working... Primes which contain only one odd number: 3 5 7 23 29 41 43 47 61 67 83 89 223 227 229 241 263 269 281 283 401 409 421 443 449 461 463 467 487 601 607 641 643 647 661 683 809 821 823 827 829 863 881 883 887 Found 45 prime numbers done...