RosettaCodeData/Task/Digital-root/ASIC/digital-root.asic

29 lines
449 B
Plaintext

REM Digital root
DATA 1&, 14&, 267&, 8128&, 39390&, 588225&, 627615&
FOR I = 0 TO 6
READ A&
N& = A&
Base = 10
GOSUB CalcDRootAndPers:
PRINT A&;
PRINT Pers;
PRINT Root
NEXT I
END
CalcDRootAndPers:
REM Results: Root - digital root; Pers - persistance
Pers = 0
WHILE N& >= Base
S = 0
Loop:
NModBase& = N& MOD Base
S = S + NModBase&
N& = N& / Base
IF N& > 0 THEN Loop:
Pers = Pers + 1
N& = S
WEND
Root = N&
RETURN