How to resolve the algorithm Iterated digits squaring step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Iterated digits squaring step by step in the VBScript 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 VBScript programming language
Source code in the vbscript programming language
start_time = Now
cnt = 0
For i = 1 To 100000000
n = i
sum = 0
Do Until n = 1 Or n = 89
For j = 1 To Len(n)
sum = sum + (CLng(Mid(n,j,1))^2)
Next
n = sum
sum = 0
Loop
If n = 89 Then
cnt = cnt + 1
End If
Next
end_time = Now
WScript.Echo "Elapse Time: " & DateDiff("s",start_time,end_time) &_
vbCrLf & "Count: " & cnt
You may also check:How to resolve the algorithm Binary digits step by step in the Fortran programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Swift programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the Simula programming language
You may also check:How to resolve the algorithm DNS query step by step in the Java programming language
You may also check:How to resolve the algorithm Entropy step by step in the Jsish programming language