How to resolve the algorithm Babbage problem step by step in the VBScript programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Babbage problem step by step in the VBScript programming language

Table of Contents

Problem Statement

Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example: He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.

The task is to find out if Babbage had the right answer — and to do so, as far as your language allows it, in code that Babbage himself would have been able to read and understand. As Babbage evidently solved the task with pencil and paper, a similar efficient solution is preferred. For these purposes, Charles Babbage may be taken to be an intelligent person, familiar with mathematics and with the idea of a computer; he has written the first drafts of simple computer programmes in tabular form. [Babbage Archive Series L].

The aim of the task is to write a program that is sufficiently clear and well-documented for such a person to be able to read it and be confident that it does indeed solve the specified problem.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Babbage problem step by step in the VBScript programming language

Source code in the vbscript programming language

'Sir, this is a script that could solve your problem.

'Lines that begin with the apostrophe are comments. The machine ignores them.

'The next line declares a variable n and sets it to 0. Note that the
'equals sign "assigns", not just "relates". So in here, this is more
'of a command, rather than just a mere proposition.
n = 0

'Starting from the initial value, which is 0, n is being incremented
'by 1 while its square, n * n (* means multiplication) does not have
'a modulo of 269696 when divided by one million. This means that the
'loop will stop when the smallest positive integer whose square ends
'in 269696 is found and stored in n. Before I forget, "<>" basically
'means "not equal to".
Do While ((n * n) Mod 1000000) <> 269696
    n = n + 1 'Increment by 1.
Loop

'The function "WScript.Echo" displays the string to the monitor. The
'ampersand concatenates strings or variables to be displayed.
WScript.Echo("The smallest positive integer whose square ends in 269696 is " & n & ".")
WScript.Echo("Its square is " & n*n & ".")

'End of Program.

  

You may also check:How to resolve the algorithm Long year step by step in the CLU programming language
You may also check:How to resolve the algorithm Function composition step by step in the Wortel programming language
You may also check:How to resolve the algorithm Loop over multiple arrays simultaneously step by step in the C programming language
You may also check:How to resolve the algorithm Variadic function step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the XPL0 programming language