Narcissistic decimal number: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) |
SqrtNegInf (talk | contribs) 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 |
Simple version using a naive predicate. |
||
<lang perl> |
<lang perl>use v5.36; |
||
⚫ | |||
sub is_narcissistic ($n) { |
|||
my($k,$sum) = (length($n),0); |
|||
my($k, $sum) = (length $n, 0); |
|||
$ |
$sum += $_**$k for split '', $n; |
||
⚫ | |||
} |
} |
||
my $i = 0; |
|||
my ($i,@N) = 0; |
|||
while (@N < 25) { |
|||
$i++ while |
$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}}== |