Pan base non-primes: Difference between revisions

Content added Content deleted
m (→‎{{header|ALGOL 68}}: tweak and emove duplicate declaration)
(julia example)
Line 184: Line 184:
100*(+/%#)2|1+I.pbnp 1+i.1e3 NB. percent odd pan based non primes up to 1000
100*(+/%#)2|1+I.pbnp 1+i.1e3 NB. percent odd pan based non primes up to 1000
16.9761</lang>
16.9761</lang>

=={{header|Julia}}==
<lang ruby>using Primes

ispanbasecomposite(n) = (d = digits(n); !isprime(n) && all(b -> !isprime(evalpoly(b, d)), maximum(d)+1:n))

panbase2500 = filter(ispanbasecomposite, 2:2500)
oddpanbase2500 = filter(isodd, panbase2500)
ratio = length(oddpanbase2500) // length(panbase2500)

println("First 50 pan base non-primes:")
foreach(p -> print(lpad(p[2], 4), p[1] % 10 == 0 ? "\n" : ""), pairs(panbase2500[1:50]))

println("\nFirst 20 odd pan base non-primes:")
foreach(p -> print(lpad(p[2], 4), p[1] % 10 == 0 ? "\n" : ""), pairs(oddpanbase2500[1:20]))

println("\nCount of pan-base composites up to and including 2500: ", length(panbase2500))

println("Odd up to and including 2500: ", ratio, ", or ", Float16(ratio * 100), "%.")
println("Even up to and including 2500: ", 1 - ratio, ", or ", Float16((1.0 - ratio) * 100), "%.")
</lang>{{out}}
<pre>
First 50 pan base non-primes:
4 6 8 9 20 22 24 26 28 30
33 36 39 40 42 44 46 48 50 55
60 62 63 64 66 68 69 70 77 80
82 84 86 88 90 93 96 99 100 110
112 114 116 118 120 121 130 132 134 136

First 20 odd pan base non-primes:
9 33 39 55 63 69 77 93 99 121
143 165 169 187 231 253 273 275 297 299

Count of pan-base composites up to and including 2500: 953
Odd up to and including 2500: 161//953, or 16.89%.
Even up to and including 2500: 792//953, or 83.1%.
</pre>



=={{header|Pascal}}==
=={{header|Pascal}}==