Narcissistic decimal number: Difference between revisions
Content added Content deleted
(→{{header|BQN}}: Array-based method) |
(Added XPL0 example.) |
||
Line 4,528: | Line 4,528: | ||
<pre> |
<pre> |
||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315] |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315] |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
This is based on Ring's version for Own Digits Power Sum. |
|||
<lang XPL0>func IPow(A, B); \A^B |
|||
int A, B, T, I; |
|||
[T:= 1; |
|||
for I:= 1 to B do T:= T*A; |
|||
return T; |
|||
]; |
|||
int Count, M, N, Sum, T, Dig; |
|||
[Text(0, "0 "); |
|||
Count:= 1; |
|||
for M:= 1 to 9 do |
|||
for N:= IPow(10, M-1) to IPow(10, M)-1 do |
|||
[Sum:= 0; |
|||
T:= N; |
|||
while T do |
|||
[T:= T/10; |
|||
Dig:= rem(0); |
|||
Sum:= Sum + IPow(Dig, M); |
|||
]; |
|||
if Sum = N then |
|||
[IntOut(0, N); ChOut(0, ^ ); |
|||
Count:= Count+1; |
|||
if Count >= 25 then exit; |
|||
]; |
|||
]; |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 548834 1741725 4210818 9800817 9926315 |
|||
</pre> |
</pre> |
||