The problem statement from the Ole Miss Problems of the Week page is:
32 × 46 = 1472
23 × 64 = 1472
Notice that the product of 32 and 46 and the product of the reverse of these numbers is identical. Find two other two-digit numbers (with different digits) that share this special phenomenon.
Well, this looks like a perfectly straightforward search of a problem space, well within the capabilities of a — how could we have possibly expected it? — programmable calculator such as the CFX-9850G or FX-7400G. On the other hand, every time we jump into writing a program without thinking, we regret it. So this time, for once, let us think first.
Hmm, two two-digit numbers. Suppose the first number is ab (a is the tens digit, b is the units digit) and the second number is cd (similarly c is the tens digit and d the units digit here). The value of the first number is 10a+b, and the value of the second number is 10c+d. Since ab is a two-digit number, a≠0. Similarly, c≠0. Since we want ba and dc to also be two-digit numbers, b≠0 and d≠0. The phrase “with different digits” means a, b, c, and d are all distinct. To avoid generating the same numbers backwards, we can assume a<b. Finally, to avoid discovering the same pair twice, we can assume ab<cd.
Hah. Okay, so the constraints are:
This is a fairly complex set of constraints, but one which severely limits the candidates our program has to examine. This is good: the program will run quickly.
We straightforwardly code up the program, available here as text or as a text file with .CAT file contents, and as always with semicolon (“;”) indicating the start of a comment not to be entered into the calculator:
; Variables: ; A is a, tens digit of first number ; B is b, ones digit of first number ; C is c, tens digit of second number ; D is d, ones digit of second number ; Symbols: ; -> is assignment arrow ; <> is not equal comparision ; = is equality comparison ; _ is display triangle For 1->A To 7 ; Test all possible As For A+1->B To 9 ; Test all possible Bs For A+1->C To 9 ; Test all possible Cs If C<>B ; Check if B and C are distinct Then For 1->D To 9 ; If so, test all possible Ds If D<>A And D<>B And D<>C; Test if D differs from all of A, B, C Then If (10A+B)(10C+D)=(10B+A)(10D+C) ; See if multiplication works both ways Then 100(10A+B)+(10C+D)_; If so, display number pair IfEnd ; [End if test same product both ways] IfEnd ; [End of test D differs from A, B, C.] Next ; [End of test all possible Ds.] IfEnd ; [End of check if A, B, C are all distinct.] Next ; [End of test all possible Cs.] Next ; [End of test all possible Bs.] Next ; [End of test all possible As.] "Done" ; Report we are done
So, we run this program and we get the following number pairs (represented as four digit numbers: 12,63 is represented as 1263, for example):
12,63 23,96 34,86 12,84 24,63 36,42 13,62 26,31 36,84 14,82 26,93 39,62 23,64 28,41 48,63
and then the program says:
Done
Great! We have our answer. But are we satisfied? Of course not.
The pairs are rather interesting. Look at 12,63: the digits in the second pair are multiples of the digits in the first pair. Similarly for 12,84, 13,62, 14,82, 23,64, and 23,96. The digits in the pair 24,63 are multiples of 1 and 2. What is going on here?
We go back to the original problem statement, where the product of the numbers is the same as the product of the number with the digits reversed. This can be written (10a+b)(10c+d) = (10b+a)(10d+c), and this means:
(10a+b)(10c+d) = (10b+a)(10d+c), or
100ac + 10ad + 10bc + bd = 100bd + 10ad + 10bc + ac, or
99ac = 99bd, or
ac = bd, or
c = bd/a
So picking 1 for a, 2 for b, and 3 for d gives 6 for c: 12 and 63. 1, 2, 4 gives 8: 12 and 84. 1, 3, 2 gives 6: 13 and 62. And so on through the list. We can write them down faster than the calculator can find them.
Okay, so next time we think more before we code.
[ Previous page | Top of page | Next page ]
Copyright © 2001 Brian Hetrick
Page last updated 25 November 2001.