

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




 
[Babbage problem from Rosetta Code website]
[EDSAC program, Initial Orders 2]
 
[Library subroutine M3. Pauses the loading, prints header,
  and gets overwritten when loading resumes.
Here, the last character sets the teleprinter to figures.]
 PFGKIFAFRDLFUFOFE@A6FG@E8FEZPF
 @&*SOLUTION!TO!BABBAGE!PROBLEM@&#
        ..PZ   [blank tape, needed to mark end of header text]
 
[Library subroutine P6. Prints strictly positive integer.
32 locations; argument at 0, working locations 1, 4, 5]
        T56K   [define load address for subroutine]
        GKA3FT25@H29@VFT4DA3@TFH30@S6@T1FV4DU4DAFG26@
        TFTFO5FA4DF4FS4FL4FT4DA1FS3@G9@EFSFO31@E20@J995FJF!F
 
               [Main routine. Load after subroutine P6.
                Must be at an even address because each double
                value at the start must be at an even address.]
        T88K   [define absolute load address]
        GK     [set @ (theta) for relative addresses]
 
               [Variables]
    [0] PF PF     [trial solution, call it n]
    [2] PF PF     [residue of n^2 modulo 1000000]
    [4] PF PF     [1st difference for n^2]
 
               [Constants]
    [6] P64F PF   [2nd difference for n^2, i.e. 128]
    [8] P4F  PF   [1st difference for n, i.e. 8]
        T10#Z PF T10Z  [clears sandwich digit between 10 and 11;
                        cf. Wilkes, Wheeler & Gill, 1951, pp 110, 141-2]
   [10] #1760F V2046F  [-1000000]
        T12#Z PF T12Z  [clears sandwich digit between 12 and 13]
   [12] Q1728F PD      [269696]
   [14] &F     [line feed]
   [15] @F     [carriage return]
   [16] K4096F [teleprinter null]
 
           [Enter with acc = 0]
   [17] T#@    [trial number n := 0]
        T2#@   [(n^2 mod 1000000) := 0]
        S6#@   [acc := -128]
        RD     [right shift]
        T4#@   [(1st difference for n^2) := -64]
 
           [Start of loop]                       
   [22] TF     [clear acc]
        A#@    [load n]
        A8#@   [add 8]
        T#@    [update n]
        A4#@   [load 1st difference of n^2]
        A6#@   [add 128]
        T4#@   [update]
        A2#@   [load residue of n^2 mod 1000000]
        A4#@   [add 1st difference]
   [31] A10#@  [subtract 1000000, by adding -1000000]
        E31@   [repeat until result < 0]
        S10#@  [add back 1000000]
        U2#@   [update residue]
        S12#@  [subtract target 269696]
        G22@   [loop back if residue < 269696]
               [if still here, acc is non-neg mult of 64]
        S8#@   [test for acc = 0 by subtracting 8]
        E22@   [loop back if residue > 269696]
 
           [Here with the solution]
        TF     [clear acc]
        A#@    [load solution n]
        TD     [store at absolute address 0 for printing]
   [42] A42@   [for return from subroutine]
        G56F   [call subroutine to print n]
        O15@   [print CR]
        O14@   [print LF]
        O16@   [print null, to flush printer buffer]
        ZF     [stop]
        E17Z   [define entry point]
        PF     [enter with acc = 0]
 