Pan base non-primes: Difference between revisions

Content added Content deleted
(Added Perl)
m (→‎{{header|Perl}}: oops, off-by-one)
Line 487: Line 487:
say "First 50 pan-base composites:\n" . table 10, @np[0..49];
say "First 50 pan-base composites:\n" . table 10, @np[0..49];
say "First 20 odd pan-base composites:\n" . table 10, (grep { 0 != $_ % 2 } @np)[0..19];
say "First 20 odd pan-base composites:\n" . table 10, (grep { 0 != $_ % 2 } @np)[0..19];
say "Count of pan-base composites up to and including $max:" . (1 + (my $f = firstidx { $max <= $_ } @np));
say "Count of pan-base composites up to and including $max: ". (my $f = 1 + firstidx { $max <= $_ } @np);
say "Percent odd up to and including $max: " . sprintf '%.3f', 100 * scalar(grep { 0 != $_ % 2 } @np[0..$f]) / $f;
say "Percent odd up to and including $max: " . sprintf '%.3f', 100 * (grep { 0 != $_ % 2 } @np[0..$f-1]) / $f;
say "Percent even up to and including $max: " . sprintf '%.3f', 100 * scalar(grep { 0 == $_ % 2 } @np[0..$f]) / $f;</syntaxhighlight>
say "Percent even up to and including $max: " . sprintf '%.3f', 100 * (grep { 0 == $_ % 2 } @np[0..$f-1]) / $f;</syntaxhighlight>
{{out}}
{{out}}
<pre>First 50 pan-base composites:
<pre>First 50 pan-base composites:
Line 503: Line 503:


Count of pan-base composites up to and including 2500: 953
Count of pan-base composites up to and including 2500: 953
Percent odd up to and including 2500: 16.912
Percent odd up to and including 2500: 16.894
Percent even up to and including 2500: 83.193</pre>
Percent even up to and including 2500: 83.106</pre>


=={{header|Phix}}==
=={{header|Phix}}==