Primes which contain only one odd digit: Difference between revisions
Content added Content deleted
(Created page with "{{Draft task}} ;Task:Primes which contain only one odd number, where '''n < 1,000''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" see "working..." + nl see "...") |
|||
Line 4: | Line 4: | ||
<br><br> |
<br><br> |
||
=={{header|Julia}}== |
|||
If only one digit of a prime is odd, then that odd digit is the ones place digit. |
|||
<lang julia>using Primes |
|||
function makeoneoddprimes(N, base = 10) |
|||
found = Int[] |
|||
for p in primes(N) |
|||
d = digits(p, base = base) |
|||
isodd(first(d)) && all(iseven, d[begin+1:end]) && push!(found, p) |
|||
end |
|||
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(sort!(found))) |
|||
end |
|||
makeoneoddprimes(1000) |
|||
</lang>{{out}} |
|||
<pre> |
|||
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 |
|||
</pre> |
|||
=={{header|Ring}}== |
=={{header|Ring}}== |