Disarium numbers

From Rosetta Code
Revision as of 16:52, 12 February 2022 by Thundergnat (talk | contribs) (New draft task and Raku example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Disarium numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

A Disarium number is an integer where the sum of each digit raised to to 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



Raku

Not an efficient algorithm. First 18 in less than 1/4 second. 19th in around 47 seconds. Pretty much unusable for the 20th. <lang perl6>my $disarium = (^∞).hyper.map: { $_ if $_ == sum .polymod(10 xx*).reverse Z** 1..* };

put $disarium[^18]; put $disarium[18];</lang>

Output:
0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427
2646798