Pan base non-primes: Difference between revisions
m
syntax highlighting fixup automation
m (→{{header|Julia}}: cleanup) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 53:
=={{header|ALGOL 68}}==
{{Trans|Wren}}
<
PR read "primes.incl.a68" PR # include prime utilities #
INT limit = 2500;
Line 150:
)
)
END</
{{out}}
<pre>
Line 170:
=={{header|J}}==
Implementation:<
digits=. 10 #.inv y
*/0=1 p: ((>./digits)+i.y) #."0 1 digits
}}"0</
Task examples:<
1 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
20{.(#~ 2&|)1+I.pbnp 1+i.1e3 NB. first 20 odd pan based non primes
Line 183:
64
100*(+/%#)2|1+I.pbnp 1+i.1e3 NB. percent odd pan based non primes up to 1000
16.9761</
=={{header|Julia}}==
<
ispanbasecomposite(n) = (d = digits(n); all(b -> !isprime(evalpoly(b, d)), maximum(d)+1:max(10, n)))
Line 204:
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), "%.")
</
<pre>
First 50 pan base non-primes:
Line 224:
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<
program PanBaseNonPrime;
// Check Pan-Base Non-Prime
Line 452:
END.
</syntaxhighlight>
{{out}}
<pre>
Line 473:
=={{header|Phix}}==
{{trans|Wren}}
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">lim</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2500</span>
Line 509:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Number odd = %3d or %9.6f%%\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">oc</span><span style="color: #0000FF;">,</span><span style="color: #000000;">oc</span><span style="color: #0000FF;">/</span><span style="color: #000000;">tc</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">})</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Number even = %3d or %9.6f%%\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">ec</span><span style="color: #0000FF;">,</span><span style="color: #000000;">ec</span><span style="color: #0000FF;">/</span><span style="color: #000000;">tc</span><span style="color: #0000FF;">*</span><span style="color: #000000;">100</span><span style="color: #0000FF;">})</span>
<!--</
Output same as Wren
=={{header|Raku}}==
<syntaxhighlight lang="raku"
use List::Divvy;
Line 525:
put "Percent odd up to and including $threshold: " ~ +@np.&upto($threshold).grep(* % 2) / +@np.&upto($threshold) × 100;
put "Percent even up to and including $threshold: " ~ +@np.&upto($threshold).grep(* %% 2) / +@np.&upto($threshold) × 100;</
{{out}}
<pre>First 50 pan-base composites:
Line 545:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "./fmt" for Fmt
Line 588:
var c
Fmt.print("Number odd = $3d or $9.6f\%", c = odd.count, c/tc * 100)
Fmt.print("Number even = $3d or $9.6f\%", c = tc - c, c/tc * 100) </
{{out}}
|