Narcissistic decimal number: Difference between revisions

Content added Content deleted
m (→‎{{header|Perl}}: now with v5.36, add output)
Line 3,463: Line 3,463:


=={{header|Perl}}==
=={{header|Perl}}==
Simple version using a naive predicate. About 15 seconds.
Simple version using a naive predicate.
<lang perl>sub is_narcissistic {
<lang perl>use v5.36;

my $n = shift;
sub is_narcissistic ($n) {
my($k,$sum) = (length($n),0);
$sum += $_**$k for split(//,$n);
my($k, $sum) = (length $n, 0);
$n == $sum;
$sum += $_**$k for split '', $n;
$n == $sum
}
}

my $i = 0;
for (1..25) {
my ($i,@N) = 0;
while (@N < 25) {
$i++ while !is_narcissistic($i);
$i++ while not is_narcissistic $i;
say $i++;
push @N, $i++
}</lang>
}

say join ' ', @N;</lang>
{{out}}
<pre>0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 548834 1741725 4210818 9800817 9926315</pre>


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