Narcissistic decimal number: Difference between revisions

add RPL
(→‎OCaml: speedup by 4.5 with pre-calculated powers)
(add RPL)
Line 4,737:
return nr
</syntaxhighlight>
 
=={{header|Ruby}}==
We started the challenge on a genuine HP-28S, powered by a 4-bit CPU running at 2 MHz.
≪ DUP XPON 1 + → n m
≪ 0 n '''WHILE''' DUP '''REPEAT'''
10 MOD LAST / IP SWAP m ^ ROT + SWAP '''END'''
DROP n ==
≫ ≫ ‘'''NAR6?'''’ STO
≪ { 0 } 1 999 '''FOR''' n IF n '''NAR6?''' '''THEN''' n + '''END'''
≫ 'TASK' STO
It took 4 minutes and 20 seconds to get the first 14 numbers.
{{out}}
<pre>
1: { 1 2 3 4 5 6 7 8 9 153 370 371 407 }
</pre>
Then we switched to the emulator, using 3-digit addition tables.
{{works with|Halcyon Calc|4.2.7}}
≪ → m
≪ { 999 } 0 CON
0 9 '''FOR''' h 0 9 '''FOR''' t 0 9 '''FOR''' u
'''IF''' h t u + + '''THEN''' h 100 * t 10 * u + + h m ^ t m ^ u m ^ + + PUT '''END NEXT NEXT NEXT'''
''''POWM'''' STO
≫ ≫ ''''INIT'''' STO
≪ DUP XPON 1 + → n m
≪ 0 n
'''WHILE''' DUP '''REPEAT'''
1000 MOD LAST / IP
'''IF''' SWAP '''THEN''' LAST '''POWM''' SWAP GET ROT + SWAP '''END'''
'''END''' DROP n ==
≫ ≫ ''''NAR6?'''' STO
≪ DUP INIT DUP ALOG SWAP 1 - ALOG
'''WHILE''' DUP2 > '''REPEAT'''
'''IF''' DUP '''NAR6? THEN''' ROT OVER + ROT ROT '''END'''
1 +
'''END''' DROP2 ≫ ''''RTASK'''' STO
{{in}}
<pre>
{ 0 } 1 RTASK 2 RTASK 3 RTASK 4 RTASK 5 RTASK 6 RTASK
</pre>
Emulator's watchdog timer has limited the quest to the first 19 Armstrong numbers.
{{out}}
<pre>
1: { 0 1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 548834 }
</pre>
 
=={{header|Ruby}}==
1,150

edits