Digital root: Difference between revisions

add RPL
(add OCaml)
(add RPL)
Line 4,008:
return s
</syntaxhighlight>
 
=={{header|RPL}}==
Base 10 only. For other bases, use <code>DIGITS</code> from [[Factors of an integer#RPL]] instead of <code>∑DGIT</code> below, which is more compact - but works only in base 10.
≪ 0 SWAP
'''DO''' 10 / LAST MOD ROT + RND SWAP FLOOR
'''UNTIL''' DUP NOT '''END''' DROP
≫ ''''∑DGIT'''' STO
≪ 0 '''WHILE''' OVER 9 > '''REPEAT'''
1 + SWAP '''∑DGIT''' SWAP '''END''' R→C
≫ ''''DROOT'''' STO
 
≪ { 627615 39390 588225 393900588225 55 } → cases
≪ {} 1 cases SIZE '''FOR''' j cases j GET '''DROOT''' + '''NEXT'''
≫ ≫ EVAL
{out}
<pre>
1: { (9,2) (6,2) (3,2) (9,2) (1,2) }
</pre>
 
=={{header|Ruby}}==
1,150

edits