A Disarium number is an integer where the sum of each digit raised to the power of its position in the number, is equal to the number.



E.G.
135 is a Disarium number:

 11 + 32 + 53 == 1 + 9 + 125 == 135

There are a finite number of Disarium numbers.



Task
 Find and display the first 18 Disarium numbers.


Stretch
 Find and display all 20 Disarium numbers.


See also
 Geeks for Geeks - Disarium numbers
 OEIS:A032799 - Numbers n such that n equals the sum of its digits raised to the consecutive powers (1,2,3,...)
 Related task: Narcissistic decimal number
 Related task: Own digits power sum Which seems to be the same task as Narcissistic decimal number...




 
# syntax: GAWK -f DISARIUM_NUMBERS.AWK
BEGIN {
    stop = 19
    printf("The first %d Disarium numbers:\n",stop)
    while (count < stop) {
      if (is_disarium(n)) {
        printf("%d ",n)
        count++
      }
      n++
    }
    printf("\n")
    exit(0)
}
function is_disarium(n,  leng,sum,x) {
    x = n
    leng = length(n)
    while (x != 0) {
      sum += (x % 10) ^ leng
      leng--
      x = int(x/10)
    }
    return((sum == n) ? 1 : 0)
}
 