Inconsummate numbers in base 10: Difference between revisions

Added Perl
(→‎{{header|Phix}}: extended to 100kth)
(Added Perl)
Line 369:
 
Real time: 3.342 s CPU share: 99.16 %
</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl" line>use v5.36;
use List::Util <sum max>;
 
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 $upto = 1e6;
my @cons = (0) x $upto;
for my $i (1..$upto) {
my $r = $i / sum split '', $i;
$cons[$r] = 1 if $r eq int $r;
}
my @incons = grep { $cons[$_]==0 } 1..$#cons;
 
say 'First fifty inconsummate numbers (in base 10):';
say table 10, @incons[0..49];
say "One thousandth: " . $incons[999];
</syntaxhighlight>
{{out}}
<pre>First fifty inconsummate numbers (in base 10):
62 63 65 75 84 95 161 173 195 216
261 266 272 276 326 371 372 377 381 383
386 387 395 411 416 422 426 431 432 438
441 443 461 466 471 476 482 483 486 488
491 492 493 494 497 498 516 521 522 527
 
One thousandth: 6996
</pre>
 
2,392

edits