 Puzzles

2001/2002 Puzzles

18 June 2001 (Crazy Digits)

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

Imagine that a two digit number is seven times the sum of its digits. After the digits of the number are reversed, you notice that the new number is W times greater than the sum of its digits.

Part 1: Will W be the same value for all two digit numbers that are seven times the sum of its digits?

Part 2: If your answer to part 1 is “yes,” what is the value of W?

Before we go on with this problem, we first note a potential ambiguity: “the new number is W times greater than the sum of its digits.” Strictly speaking, if x is w times greater than y, this means x is y plus w times y — or x = (w+1)y. Two pounds is twice one pound, but only one pound greater than one pound. Similarly, ten pounds is ten times one pound, but only nine times greater than one pound. We assume the problem meant to say “the new number is W times the sum of its digits.” If this is not correct, we will need to subtract 1 from W when we get a value for W.

Now having decided on the meaning of the question, and having our nifty programmable CFX-9850G or FX-7400G handy, we decide to write a program to answer it. We will need to generate all two digit numbers: two-digit numbers are 10 through 99, inclusive. We will need to find the separate digits of the number: divide by 10 and take the integer part of the quotient for the tens digit, subtract out the 10s factor to get the ones digit. We will need to find whether the value is 7 times the sum of the digits: compare the two values. We will need to find the number with digits reversed: 10 times the ones digit plus the tens digit. We will need to find the value of W: divide by the original value. We will need to find whether all the W values are the same: this is a little trickier.

To find whether all the W values are the same, we keep two indicators, both initialized to false, and a “first W” value. The first indicator tells whether we have ever seen a W. The second indicator tells whether we have ever seen a different W than the first W. If the first indicator is false (we have not yet seen a W), set it to true and save the W value. If the first indicator is true (we have seen a W), check if the current W value differs from the saved W value: if so, set the second indicator to true. (We cannot just set the second indicator to indicate whether this W matches the saved W, as there may be a previous mismatch, and we do not want to lose that information.) Finally, when we are done checking all the two-digit numbers, if the first indicator is true (we have seen some W) and the second indicator is false (all the Ws we have seen are the same), then the saved W value is the value of interest. Otherwise, the answer to part 1 is “no.”

This approach, however, causes us some disquiet. All the various computations — extracting the digits, summing the digits, reversing the digits, checking for four times the sum of the digits — are integer operations and so exact. Computing W, however, is taking the quotient of two integers, and this is, in general, a real number. There is therefore the possibility of identical values being computed as slightly different values due to numerical considerations, or of slightly different values being computed as identical values. We need to think about whether these are real possibilities.

Now, the W values are rational numbers with a number between 1 and 99 in the numerator, and a number between 1 and 18 in the denominator. The two closest possible W values are 99/18 and 98/18. These two values differ by over one percent, so the calculator’s computation to 15 digits will certainly result in distinct values for different Ws.

W values that are actually the same will result from one operation upon two exact numbers, and so will have an error of at most 1 in the 15th digit. It is possible for the calculator to report two numbers differing by 1 in the 15th digit as different — it is also possible for the calculator to report two numbers differing by 7 in the 15th digit as the same, depending on the values involved. So it is possible that simply computing and comparing W values will result in identical W values being reported as different. To guard against this, we compare the W values to only one part in 105. Since actual W values differ by at least one part in 100, this test will safefy distinguish W values that are actually different.

Okay: a somewhat tedious program, but an easy one.

The program is available in a text file with .CAT file contents, or here in text form. Lines and parts of lines starting with a semicolon (“;”) are comments and are not actually entered into the calculator.

```; Variables:
;   A is number we are checking
;   B is tens digit of A
;   C is ones digit of A
;   D is sum of digits of A
;   E is A with digits reversed
;   F is ratio of A with digits reversed and sum of digits
;   G is the number of Ws observed so far
;   H is first W value observed
;   I is "we have multiple Ws" flag
; Symbols:
;   -> is assignment arrow
;   / is division operator
;   = is equality relational
;   <> is inequality relational
;   > is greater than relational
;   EE is EXP key
;   (-) is change sign key

0->G               ; To start, there is no W
0->I               ; And there are not multiple Ws
For 10->A To 99    ; Loop through all two-digit numbers in A
Int (A/10)->B      ;   Extract the tens digit into B
A-10B->C           ;   Extract the ones digit into C
B+C->D             ;   Add the digits into D
If A=7D            ;   Test if A is 7 times the sum of digits
Then 10C+B->E      ;     If so, reverse the digits of A into E
E/D->F             ;     Find ratio of number with digits reversed and
;       sum of digits into F
If G=0             ;     Test whether we have a W yet
Then F->H          ;       If not, this ratio is the first W
IfEnd              ;     [End of test whether we have a W yet]
G+1->G             ;     Increment the count of Ws seen
If Abs (F-H)/F>1EE(-)5;  Test if this W different from the saved W
Then 1->I          ;       If so, set the "multiple Ws" flag
IfEnd              ;     [End of this W different from saved W test]
IfEnd              ;   [End of A is 7 times the sum of digits test]
Next               ; [End of loop through two-digit numbers A]
If G<>0 And I=0    ; Test whether we have seen at least one W, and
;   all Ws seen were the same
Then "Common W:"   ;   If so, label the report
H                  ;   and report the common W value
Else "No"          ; Otherwise say "No"
IfEnd              ; [End of test about Ws]
```

We run the program, and it produces:

```Common W:
4
```

Well, that is special. We have an answer to the question, but we have absolutely no insight into why that is the answer. So instead of writing and running a program that computes the answer, let’s think about the problem, instead.

We start with a two digit number. If a is the tens digit and b is the ones digit, the number is 10a+b. The sum of digits is a+b. If the number is 7 times the sum of digits, then

10a+b = 7(a+b), or
3a = 6b, or
a = 2b

Oh. So the numbers where the value is seven times the sum of the digits are 21, 42, 63, and 84. The number with the digits reversed is 10b+a, and if that value is W times the sum of the digits, then

W = (10b + a) / (a + b)
= (10b + 2b) / (2b + b)
= 12b / 3b
= 4

And now we not only have the answer, we understand — and it was quicker than planning, writing, debugging, and running the program, too. Page last updated 25 November 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 