### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,367)
- misc (4)
- project euler (2)
- puzzle (90)
- puzzle# (48)
- site news (58)
- tantalizer (94)
- teaser (7)

### Site Stats

- 233,130 hits

Programming Enigma Puzzles

23 March 2014

Posted by on **From New Scientist #1323, 16th September 1982** [link]

If the digits of a number are added together, and this process repeated several times, if necessary, on the numbers so formed, eventually an integer which is in the range 1 to 9 is obtained. For example, the integer obtained from the number 16886 is 2 (i.e. 1 + 6 + 8 + 8 + 6 = 29; 2 + 9 = 11; 1 + 1 = 2).

What is the integer obtained from the number (9

^{624}+ 2)^{1872}?

[enigma178]

%d bloggers like this:

Python is perfectly happy to deal with numbers as large as the one in the question. This simple Python program runs in 302ms.

Solution:The digital root of (9^{624}+ 2)^{1872}is 1.However using the properties of digital roots we can arrive the answer with minimal computation.

Firstly the digital root of a multiple of 9 is 9. So:

so:

So:

And the digital root of powers of 2 cycle through the 6 numbers: 1, 2, 4, 8, 7, 5.

And as 1872 mod 6 = 0 the solution is the first number on this list, i.e. 1.

From the Wikipedia page on Digital Roots [ https://en.wikipedia.org/wiki/Digital_root ] we see that a perfect square has a digital root of 1, 4, 7 or 9, and a perfect cube has a digital root of 1, 8 or 9. As 1872 is divisible by both 2 and 3 then the number we are interested in is both a square and a cube.

Furthermore, as shown above, the digital root of the number in question is the same as the digital root of 2

^{1872}, and the digital root of a power of 2 is 1, 2, 4, 5, 7 or 8.The only number in all three sets is 1, and this is the answer.

If you compute the number in question you find it has 1,114,678 digits if written out in decimal. Here are the first and last few digits:

The sum of all the digits is 5,013,730.

We can use the program I wrote for

Enigma 1561to compute digital roots by summing digits. It takes 4 iterations to reach the answer, the run time is 9.6s. (The vast majority of the time will be consumed producing the decimal representation of the original number).9624 mod 9 = 0

0+2=2

((0+2)^1872 ) mod 9 =?

(2^6) mod 9 =1

1872/6=312

1^312=1

Hence , the answer is 1.

And here’s a solution written in BBC Basic for the BBC Micro – a microcomputer contemporary with the puzzle. Using the same approach I used for the BBC Micro solution of

Enigma 1561.Without line 135 the BBC Micro doesn’t have enough memory to cope with the amount of recursion needed to run the program, even in

`MODE 7`

.