 Puzzles

2001/2002 Puzzles

29 January 2001 (Four Digit Surprise)

The problem statement from the Ole Miss Problems of the Week page is:

Find three consecutive odd whole numbers such that the sum of their squares is a four-digit number whose digits are all the same.

So we need to find an odd k such that

k2 + (k+2)2 + (k+4)2

is a four-digit number with all four digits the same.

We can program this fairly directly on a programmable calculator, such as the CFX-9850G or FX-7400G. We can start k at 1, and stop searching when the sum of squares above exceeds 9999. The program, available as text here or as a text file with .CAT file contents, is:

```; Variables:
;   A is the k value being tested
;   B is the sum of A square, (A+2) square, and (A+4) square
;   C is the ones digit of B
;   D is the tens digit of B
;   E is the hundreds digit of B
;   F is the thousands digit of B
; Symbols:
;   -> is assignment arrow
;   x^2 is square operator
;   >= is greater than or equal to relational
;   EE is EXP key
;   / is division operator
;   = is relational operator
;   _ is display triangle

1->A               ; Start search with 1, the first odd number
While 1            ; Loop forever (the exit test is coded inside)
Ax^2+(A+2)x^2+(A+4)x^2->B
;   Compute the sum of squares
If B>=1EE5         ;   Test whether the sum of squares is too large
Then Break         ;     If so, exit the loop
IfEnd              ;   [End of test on sum of squares]
10Frac (B/10)->C   ;   Extract the ones digit of the sum of squares
Int (10Frac (B/100))->D; Extract the tens digit
Int (10Frac (B/1000))->E; Extract the hundreds digit
Int (B/1000)->F    ;   Extract the thousands digit
If C=D And C=E And C=F;Test whether the digits are equal
Then A_            ;     If so, display the first of the odd numbers
IfEnd              ;   [End of test on equal digits]
A+2->A             ;   Go on to the next odd number
WhileEnd           ; [End of loop forever]
"Done"             ; Note program completion
```

When we run the program, it first reports:

```41
```

and then:

```Done
```

Well, 412 + 432 + 452 = 1681 + 1849 + 2025 = 5555, which indeed is a four digit number with all digits the same.

It is hard, though, to get a feeling of satisfaction from programming a simple search. Perhaps there is another way to do this problem.

We first look at this expression, k2 + (k+2)2 + (k+4)2. Expanding this out, we get

3k2 + 12k + 20.

Now how will we express that this sum is a four digit number with all four digits the same? Oh, that means the sum is 1111m for some integer m between 1 and 9 inclusive. So we have

3k2 + 12k + 20 = 1111m, or
3k2 + 12k + (20 - 1111m) = 0

Why, this is just a quadratic equation! Actually, this is nine quadratic equations, depending on the value of m. We can easily stuff the coefficients into the quadratic formula, and get results as follows:

m

k

1

-21.1746, +17.1746

2

-29.1662, +25.1662

3

-35.2916, +31.2916

4

-40.4534, +36.4534

5

-45, 41

6

-49.1098, +45.1098

7

-52.8888, +48.8888

8

-56.4059, +52.4059

9

-59.7090, +55.7090

It is only for m equal to 5 that the solutions are integers, and the solutions are -45 and 41. The three consecutive odd integers are therefore either 41, 43, and 45, or -45, -43, and -41. Clearly these are the same after you square them. Note that the mathematical solution correctly finds the negative values that we simply forgot about when doing the program — the problem did not state positive integers, we merely assumed that.

Oops. Our program cleverly solved the wrong problem. Well, that happens sometimes. Page last updated 7 August 2001.

Brian’s Casio Calculator Corner

Home

Programs

Tutorial

Puzzles

Index

2001/2002

Index

15 April 2002

11 February 2002

1 October 2001

24 September 2001

13 August 2001

30 July 2001

18 June 2001

4 June 2001

21 May 2001

7 May 2001

30 April 2001

23 April 2001

9 April 2001

18 February 2001

4 February 2001

29 January 2001

Previous years

In memoriam: Dijkstra

Site Information 