Pan base non-primes: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 53:
=={{header|ALGOL 68}}==
{{Trans|Wren}}
<langsyntaxhighlight lang="algol68">BEGIN # pan-base non-primes - translated from the Wren sample #
PR read "primes.incl.a68" PR # include prime utilities #
INT limit = 2500;
Line 150:
)
)
END</langsyntaxhighlight>
{{out}}
<pre>
Line 170:
 
=={{header|J}}==
Implementation:<langsyntaxhighlight Jlang="j">pbnp=: {{ if. 10 > y do. -.1 p: y return. end.
digits=. 10 #.inv y
*/0=1 p: ((>./digits)+i.y) #."0 1 digits
}}"0</langsyntaxhighlight>
Task examples:<langsyntaxhighlight Jlang="j"> 40{.1+I.pbnp 1+i.1e3 NB. first 40 pan based non primes
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</langsyntaxhighlight>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="ruby">using Primes
 
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), "%.")
</langsyntaxhighlight>{{out}}
<pre>
First 50 pan base non-primes:
Line 224:
=={{header|Pascal}}==
==={{header|Free Pascal}}===
<langsyntaxhighlight lang="pascal">
program PanBaseNonPrime;
// Check Pan-Base Non-Prime
Line 452:
 
END.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 473:
=={{header|Phix}}==
{{trans|Wren}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<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>
<!--</langsyntaxhighlight>-->
Output same as Wren
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>use Base::Any;
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;</langsyntaxhighlight>
{{out}}
<pre>First 50 pan-base composites:
Line 545:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "./math" for Int
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) </langsyntaxhighlight>
 
{{out}}
10,327

edits