Narcissistic decimal number: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added the REXX language. -- ~~~~)
Line 128: Line 128:
8208 9474 54748 92727 93084
8208 9474 54748 92727 93084
548834 1741725 4210818 9800817 9926315</pre>
548834 1741725 4210818 9800817 9926315</pre>

{{header|REXX}}
<lang rexx>/*REXX program to generate and display a number of narcissistic numbers.*/
numeric digits 20 /*just in case more are wanted. */
parse arg N .; if N=='' then N=25 /*get number of narcissistic #'s.*/
#=0 /*number of narcissistic # so far*/
do j=1 until #==N; L=length(j) /*get the length of the J number.*/
s=left(j,1)**L /*sum of the J digits to L power.*/
/* [↑] calculate partial sum. */
do k=2 for L-1 /*perform for each digit in J. */
s=s+substr(j,k,1)**L /*add digit raised to pow to sum.*/
if s>j then iterate j /*perform a short-circuit test. */
end /*k*/ /* [↑] calculate the rest of sum*/
/* [↓] perform final "sum" test.*/
if s\==j then iterate /*does sum equal to J? No ∙∙∙ */
#=#+1 /*bump the narcissistic num count*/
say right(#,9) ' narcissistic:' j /*display index & narcissistic #.*/
end /*j*/ /* [↑] this list starts at 1. */
/*stick a fork in it, we're done.*/</lang>