The problem statement from the Ole Miss Problems of the Week page is:
Consider the number 3025. If you tear 3025 down the middle, into 30 and 25, and take the two two-digit numbers formed by this operation, an interesting oddity occurs. The sum of 30 and 25 is 55, and the square of 55 is the original number, 3025. Find another four-digit number that shares this same oddity.
There is that word “find” again. I imagine we could write a small program that we could run on the Casio CFX-9850G or FX-7400G and find the answer. Isn’t that an amazing and novel idea? Let’s!
It seems simple enough. Generate all four-digit numbers — 1000 through 9999 — split up the top and bottom halves, add the halves together, square the sum, and test whether it equals the original number. The program is presented here and as a text file with .CAT file contents. As with our other programs, semicolon (“;”) starts a comment that is not to be entered into the calculator.
Program P091299 (74 bytes):
; Variables: ; A is four digit number being tested ; B is halves of four digit number ; Symbols: ; -> is assignment arrow ; / is division operator ; x^2 is square operator ; = is equality relational ; _ is display triangle For 1000->A To 9999; Loop through all four-digit numbers A/100->B ; Shift into upper and lower halves 100Frac B+Int B->B ; Sum the halves If Bx^2=A ; Test whether square is original number Then A_ ; If so, display original number IfEnd ; [End of test whether square is original number] Next ; [End of loop through all four-digit numbers] "Done" ; Indicate completion
We run this program, and in a minute or two it produces:
2025 3025 9801 Done
So now we know two other four-digit numbers that share the oddity.
But while we have an answer, it is not really very satisfactory. We tested all four-digit numbers, and found only three that met the criteria. There has to be a better way. Let’s think for a minute.
Suppose the top half of the number is x, and the bottom half is y. Then the value of the number is 100x + y, and the value of the square is (x + y)2 or x2 + 2xy + y2. These two have to be equal to one another. So:
Now, the square root is real only if 2500-99y is positive, which means y has to be between 0 and 25, inclusive. If y is zero, the solutions for x are degenerate: 0 and 100, neither of which yield four-digit numbers. So now we can write a small program that searches for y between 1 and 25 for an integral x.
There is one complication, though. Square root operations are approximate — we cannot assume that the square root of a perfect square is calculated as an integer. So we take the nearest integer to the calculated square root, square it, and test against the quantity 2500-99y. If we get a match, then we have an integral square root. With this small concession to numerical analysis, we have the following program.
Program P0912991 (124 bytes):
; Variables: ; A is candidate y value ; B is discrimant of square root ; C is integer nearest square root ; D is candidate value for x For 1->A To 25 ; Loop through possible y values 2500-99A->B ; Compute discriminant Int (sqrtB+.5)->C ; Get nearest integer to square root If B=Cx^2 ; Test whether integer is square root Then 50-A-C->D ; If so, compute lower root If D>0 ; Test whether lower root is positive Then 100D+A_ ; If so, display solution IfEnd ; [End of test whether lower root is positive] 50-A+C->D ; Compute upper root If D>0 ; Test whether upper root is positive Then 100D+A_ ; If so, display solution IfEnd ; [End of test whether upper root is positive] IfEnd ; [End of test whether integer is square root] Next ; [End of loop through y values] "Done" ; Indicate completion
Running this program, we very quickly get the results:
9801 2025 3025 Done
And so we have a proper search solution.
[ Previous page | Top of page | Next page ]
Copyright © 2001 Brian Hetrick
Page last updated 25 November 2001.