September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
20
Task/Digital-root/Phix/digital-root.phix
Normal file
20
Task/Digital-root/Phix/digital-root.phix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue