Digital root/Multiplicative digital root: Difference between revisions
Content added Content deleted
Line 2,355: | Line 2,355: | ||
func digroot(num) |
func digroot(num) |
||
for n = 1 to len(num) |
for n = 1 to len(num) |
||
sum = 0 |
sum = 0 |
||
numold = num[n] |
numold = num[n] |
||
while true |
while true |
||
pro = 1 |
pro = 1 |
||
strnum = string(numold) |
strnum = string(numold) |
||
for nr = 1 to len(strnum) |
for nr = 1 to len(strnum) |
||
pro = pro * number(strnum[nr]) |
pro = pro * number(strnum[nr]) |
||
next |
next |
||
sum = sum + 1 |
sum = sum + 1 |
||
numold = pro |
numold = pro |
||
numn = string(num[n]) |
numn = string(num[n]) |
||
sp = 6 - len(string(num[n])) |
sp = 6 - len(string(num[n])) |
||
if sp > 0 |
if sp > 0 |
||
for p = 1 to sp + 2 |
for p = 1 to sp + 2 |
||
numn = " " + numn |
numn = " " + numn |
||
next |
next |
||
ok |
ok |
||
if len(string(numold)) = 1 and len(num) < 5 |
if len(string(numold)) = 1 and len(num) < 5 |
||
see "" + numn + " " + numold + " " + sum + nl |
see "" + numn + " " + numold + " " + sum + nl |
||
exit |
exit |
||
ok |
ok |
||
if len(string(numold)) = 1 and len(num) > 4 |
if len(string(numold)) = 1 and len(num) > 4 |
||
root2[numold+1] = root2[numold+1] + 1 |
root2[numold+1] = root2[numold+1] + 1 |
||
if root2[numold+1] < 6 |
if root2[numold+1] < 6 |
||
root[numold+1][root2[numold+1]] = num[n] |
root[numold+1][root2[numold+1]] = num[n] |
||
ok |
ok |
||
exit |
exit |
||
ok |
ok |
||
end |
end |
||
next |
next |
||
</lang> |
</lang> |