## Teaser 2963: A result

**From The Sunday Times, 7th July 2019** [link]

For any number, I square the digits and then add the resulting numbers. If necessary, I keep repeating the process until I end up with a single digit, called the result. For example: 142 gives 1 + 16 + 4 = 21 which then gives 4 + 1 = 5, the result.

I have written down a two-digit number. If I tell you one of the digits [the key digit], you should be able to work out the result.

I then use a 3rd digit to get a three-digit number. The result of that number happens to be the key digit.

In increasing order, what are the three digits?

[teaser2963]

## Jim Randell 5:59 pm

on5 July 2019 Permalink |The following Python program runs in 90ms.

Run:[ @repl.it ]Solution:The three digits are: 5, 6, 9.The order of the digits in a number does not matter. 24 will have the same result as 42 (both are 2² + 4² = 20 → 2² + 0² = 4).

The key digit is 5. Any 2-digit sequence that contains a 5 has a result of 4.

The initial number is one of: 56, 59, 65, 95. An extra digit is added so the three digit sequence consists of the digits 5, 6, 9 (in some order). And this sequence has a result of 5.

Most of the 2-digit numbers give a result of 4, and if the process is allowed to continue summing the squares of the digits we see the following cycle emerge:

Numbers that eventually result in this cycle are known as “unhappy numbers” (see [ link ]).

The other 2-digit numbers give results of 1, 2, 5, 8, 9, we can also continue the process with these values:

We see that any numbers with a result of 2, 5, 8, 9 are also “unhappy”, and only those numbers that have a result of 1 are “happy”. (See OEIS A124095 [ link ]).

LikeLike

## Jim Randell 3:54 pm

on7 July 2019 Permalink |Here’s a simpler program to solve the puzzle.

Run:[ @repl.it ]LikeLike