Narcissistic decimal number: Difference between revisions

add UNIX Shell
(add UNIX Shell)
Line 1,197:
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|UNIX Shell}}==
{{works with|ksh93}}
<lang bash>function narcissistic {
integer n=$1 len=${#n} sum=0 i
for ((i=0; i<len; i++)); do
(( sum += pow(${n:i:1}, len) ))
done
(( sum == n ))
}
 
nums=()
for ((n=0; ${#nums[@]} < 25; n++)); do
narcissistic $n && nums+=($n)
done
echo "${nums[*]}"
echo "elapsed: $SECONDS"</lang>
 
{{output}}
<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
elapsed: 436.639</pre>
 
=={{header|zkl}}==
Anonymous user