A   Narcissistic decimal number   is a non-negative integer,   



n


{\displaystyle n}

,   that is equal to the sum of the   



m


{\displaystyle m}

-th   powers of each of the digits in the decimal representation of   



n


{\displaystyle n}

,   where   



m


{\displaystyle m}

   is the number of digits in the decimal representation of   



n


{\displaystyle n}

.



Narcissistic (decimal) numbers are sometimes called   Armstrong   numbers, named after Michael F. Armstrong.

They are also known as   Plus Perfect   numbers.



An example

   if   



n


{\displaystyle n}

   is   153 
   then   



m


{\displaystyle m}

,   (the number of decimal digits)   is   3 
   we have    13 + 53 + 33   =   1 + 125 + 27   =   153  
   and so   153   is a narcissistic decimal number


Task

Generate and show here the first   25   narcissistic decimal numbers.



Note:   




0

1


=
0


{\displaystyle 0^{1}=0}

,   the first in the series.



See also

   the  OEIS entry:     Armstrong (or Plus Perfect, or narcissistic) numbers.
   MathWorld entry:   Narcissistic Number.
   Wikipedia entry:     Narcissistic number.


scope
    # print the first 25 narcissistic numbers
 
    local power := reg( 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 );
    local count      := 0;
    local maxCount   := 25;
    local candidate  := 0;
    local prevDigits := 0;
    local digits     := 1;
 
    for d9 from 0 to 2 while count < maxCount do
        if d9 > 0 and digits < 9 then digits := 9 fi;
        for d8 from 0 to 9 while count < maxCount do
            if d8 > 0 and digits < 8 then digits := 8 fi;
            for d7 from 0 to 9 while count < maxCount do
                if d7 > 0 and digits < 7 then digits := 7 fi;
                for d6 from 0 to 9 while count < maxCount do
                    if d6 > 0 and digits < 6 then digits := 6 fi;
                    for d5 from 0 to 9 while count < maxCount do
                        if d5 > 0 and digits < 5 then digits := 5 fi;
                        for d4 from 0 to 9 while count < maxCount do
                            if d4 > 0 and digits < 4 then digits := 4 fi;
                            for d3 from 0 to 9 while count < maxCount do
                                if d3 > 0 and digits < 3 then digits := 3 fi;
                                for d2 from 0 to 9 while count < maxCount do
                                    if d2 > 0 and digits < 2 then digits := 2 fi;
                                    for d1 from 0 to 9 do
                                        if prevDigits <> digits then
                                            # number of digits has increased - increase the powers
                                            prevDigits := digits;
                                            for i from 2 to 9 do mul power[ i + 1 ], i od;
                                        fi;
                                        # sum the digits'th powers of the digits of candidate
                                        local sum := power[ d1 + 1 ] + power[ d2 + 1 ] + power[ d3 + 1 ]
                                                   + power[ d4 + 1 ] + power[ d5 + 1 ] + power[ d6 + 1 ]
                                                   + power[ d7 + 1 ] + power[ d8 + 1 ] + power[ d9 + 1 ]
                                                   ;
                                        if candidate = sum
                                        then
                                            # found another narcissistic decimal number
                                            io.write( " ", candidate );
                                            inc count, 1
                                        fi;
                                        inc candidate, 1
                                    od; # d1
                                od; # d2
                            od; # d3
                        od; # d4
                    od; # d5
                od; # d6
            od; # d7
        od; # d8
    od; # d9
    io.writeline()
 
epocs