Pan base non-primes: Difference between revisions

Added Perl
(Added Perl)
Line 470:
even up to and including 2500 = 792 equals 83.105981%
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use ntheory <fromdigits is_prime>;
use List::AllUtils <max firstidx>;
 
sub table ($c, @V) { my $t = $c * (my $w = 2 + length max @V); ( sprintf( ('%'.$w.'d')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
 
my $max = 2500;
my @np = <4 6 8 9>;
for my $n (11..$max) {
push @np, $n unless max map { max(split '',$n) < $_ and is_prime fromdigits($n,$_) } 2..$n;
}
 
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 "Count of pan-base composites up to and including $max:" . (1 + (my $f = firstidx { $max <= $_ } @np));
say "Percent odd up to and including $max: " . sprintf '%.3f', 100 * scalar(grep { 0 != $_ % 2 } @np[0..$f]) / $f;
say "Percent even up to and including $max: " . sprintf '%.3f', 100 * scalar(grep { 0 == $_ % 2 } @np[0..$f]) / $f;</syntaxhighlight>
{{out}}
<pre>First 50 pan-base composites:
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 composites:
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
Percent odd up to and including 2500: 16.912
Percent even up to and including 2500: 83.193</pre>
 
=={{header|Phix}}==
2,392

edits