

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.




 
*        Find the lowest positive integer whose square ends in 269696
*        The logic of the assembler program is simple :
*        loop for i=524 step 2
*          if (i*i modulo 1000000)=269696 then leave loop
*        next i
*        output 'Solution is: i=' i '  (i*i=' i*i ')'
BABBAGE  CSECT                     beginning of the control section
         USING BABBAGE,13          define the base register
         B     72(15)              skip savearea (72=18*4)
         DC    17F'0'              savearea (18 full words (17+1))
         STM   14,12,12(13)        prolog: save the caller registers
         ST    13,4(15)            prolog: link backwards
         ST    15,8(13)            prolog: link forwards
         LR    13,15               prolog: establish addressability
         LA    6,524               let register6 be i and load 524
LOOP     LR    5,6                 load register5 with i
         MR    4,6                 multiply register5 with i
         LR    7,5                 load register7 with the result i*i
         D     4,=F'1000000'       divide register5 with 1000000
         C     4,=F'269696'        compare the reminder with 269696
         BE    ENDLOOP             if equal branch to ENDLOOP
         LA    6,2(6)              load register6 (i) with value i+2
         B     LOOP                branch to LOOP
ENDLOOP  XDECO 6,BUFFER+15         edit registrer6 (i)
         XDECO 7,BUFFER+34         edit registrer7 (i squared)
         XPRNT BUFFER,L'BUFFER     print buffer
         L     13,4(0,13)          epilog: restore the caller savearea
         LM    14,12,12(13)        epilog: restore the caller registers
         XR    15,15               epilog: set return code to 0
         BR    14                  epilog: branch to caller
BUFFER   DC    CL80'Solution is: i=............  (i*i=............)'
         END   BABBAGE             end of the control section
 