How to resolve the algorithm Iterated digits squaring step by step in the XPL0 programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Iterated digits squaring step by step in the XPL0 programming language
Table of Contents
Problem Statement
If you add the square of the digits of a Natural number (an integer bigger than zero), you always end with either 1 or 89: An example in Python:
Or, for much less credit - (showing that your algorithm and/or language is slow): This problem derives from the Project Euler problem 92. For a quick algorithm for this task see the talk page
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Iterated digits squaring step by step in the XPL0 programming language
Source code in the xpl0 programming language
int C, N, M, S;
[C:= 0;
for N:= 1 to 100_000_000-1 do
[M:= N;
loop [S:= 0;
repeat M:= M/10;
S:= S + rem(0)*rem(0);
until M = 0;
if S = 89 then
[C:= C+1; quit];
if S = 1 then quit;
M:= S;
];
];
IntOut(0, C);
]
You may also check:How to resolve the algorithm Deconvolution/2D+ step by step in the Ursala programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Luck programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Frink programming language
You may also check:How to resolve the algorithm Flipping bits game step by step in the Scala programming language
You may also check:How to resolve the algorithm Average loop length step by step in the Scheme programming language