user
Charles Babbage

Charles Babbage's analytical engine.

Charles Babbage, looking ahead to the sorts of problems his Analytical Engine would be able to solve, gave this example:

What is the smallest positive integer whose square ends in the digits 269,696?

— Babbage, letter to Lord Bowden, 1837; see Hollingdale and Tootill, *Electronic Computers*, second edition, 1970, p. 125.

He thought the answer might be 99,736, whose square is 9,947,269,696; but he couldn't be certain.

Task

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].

Motivation

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.
assistant
(formerly Perl 6)

This could certainly be written more concisely. Extra verbiage is included to make the process more clear.

```
# For all positive integers from 1 to Infinity
for 1 .. Inf -> $integer {
    
    # calculate the square of the integer
    my $square = $integer²;
    
    # print the integer and square and exit if the square modulo 1000000 is equal to 269696
    print "{$integer}² equals $square" and exit if $square mod 1000000 == 269696;
}

```

Output:

```
25264² equals 638269696
```

More concisely (but clear enough to allow Mr. Babbage to understand what's going on?):

```
.say and exit if $_²  % 1e6 == 269696 for ^∞;

```

Output:

```
25264
```

Notice that `exit` ends the process itself instead of ending just the loop, as `last` would. `exit` would arguably be easier to understand for Babbage though, so it may better fill the task requirement.