How to resolve the algorithm Digital root step by step in the Nanoquery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Digital root step by step in the Nanoquery programming language
Table of Contents
Problem Statement
The digital root,
X
{\displaystyle X}
, of a number,
n
{\displaystyle n}
, is calculated: The additive persistence is the number of summations required to obtain the single digit. The task is to calculate the additive persistence and the digital root of a number, e.g.: The digital root may be calculated in bases other than 10.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Digital root step by step in the Nanoquery programming language
Source code in the nanoquery programming language
def digital_root(n)
ap = 0
n = +(int(n))
while n >= 10
sum = 0
for digit in str(n)
sum += int(digit)
end
n = sum
ap += 1
end
return {ap, n}
end
println "here"
if main
values = {627615, 39390, 588825, 393900588225, 55}
for n in values
aproot = digital_root(n)
println format("%12d has additive persistence %2d and digital root %d.", n, aproot[0], aproot[1])
end
end
You may also check:How to resolve the algorithm Generate lower case ASCII alphabet step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Maple programming language
You may also check:How to resolve the algorithm Chaos game step by step in the Logo programming language
You may also check:How to resolve the algorithm String case step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Wren programming language