Narcissistic decimal number: Difference between revisions
Content added Content deleted
(New draft task and Python solution.) |
(Perl 6 entry) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
A [http://mathworld.wolfram.com/NarcissisticNumber.html Narcissistic decimal number] is a positice decimal number, <math>n</math> in which if there are <math>m</math> digits in the |
A [http://mathworld.wolfram.com/NarcissisticNumber.html Narcissistic decimal number] is a positice decimal number, <math>n</math> in which if there are <math>m</math> digits in the number then the sum of all the individual digits of the number raised to the power <math>m</math> is equal to <math>n</math>. |
||
For example, if <math>n</math> is 153 then <math>m</math>, the number of digits is 3 and we have <math>1^3+5^3+3^3 = 1+125+27 = 153</math> and so 153 is a narcissistic decimal number. |
For example, if <math>n</math> is 153 then <math>m</math>, the number of digits is 3 and we have <math>1^3+5^3+3^3 = 1+125+27 = 153</math> and so 153 is a narcissistic decimal number. |
||
The task is to generate and show here, the first 25 narcissistic numbers. |
The task is to generate and show here, the first 25 narcissistic numbers. |
||
=={{header|Perl6}}== |
|||
Here is a straightforward, naive implementation. Should work but takes ages. |
|||
<lang perl6>sub is-narcissic(Int $n) { $n == ([+] $n.comb)**$n.chars } |
|||
say (grep &is-narcissic, 0 .. *)[^15];</lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |