21 lines
514 B
Plaintext
21 lines
514 B
Plaintext
procedure digital_root(atom n, integer base=10)
|
|
integer root, persistence = 1
|
|
atom work = n
|
|
while 1 do
|
|
root = 0
|
|
while work!=0 do
|
|
root += remainder(work,base)
|
|
work = floor(work/base)
|
|
end while
|
|
if root<base then exit end if
|
|
work = root
|
|
persistence += 1
|
|
end while
|
|
printf(1,"%15d root: %d persistence: %d\n",{n,root,persistence})
|
|
end procedure
|
|
|
|
digital_root(627615)
|
|
digital_root(39390)
|
|
digital_root(588225)
|
|
digital_root(393900588225)
|