Enigmatic Code

Programming Enigma Puzzles

Enigma 178: A high-powered sum

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 (9624 + 2)1872?

[enigma178]

5 responses to “Enigma 178: A high-powered sum

  1. Jim Randell 23 March 2014 at 9:21 am

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

    from enigma import digrt
    
    print(digrt((9 ** 624 + 2) ** 1872))
    

    Solution: The digital root of (9624 + 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:

    dr(9624) = 9

    so:

    dr(9624 + 2) = dr(9 + 2) = 2

    So:

    dr((9624) + 2)1872) = dr(21872)

    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.

    • Jim Randell 23 March 2014 at 11:17 am

      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 21872, 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.

    • Jim Randell 23 March 2014 at 2:34 pm

      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:

      24778005196312737960...32299713157259913281

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

      We can use the program I wrote for Enigma 1561 to 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).

      % time pypy enigma1561.py "(9 ** 624 + 2) ** 1872"
      [24778005196312737960...32299713157259913281 => 5013730]
      [5013730 => 19]
      [19 => 10]
      [10 => 1]
      1
      pypy enigma1561.py "(9 ** 624 + 2) ** 1872"  9.38s user 0.06s system 98% cpu 9.588 total
      
  2. Naim Uygun 23 March 2014 at 10:26 am

    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.

  3. Jim Randell 23 March 2014 at 4:21 pm

    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.

    >LIST
       10 start% = TIME
       20 PRINT "checksum = ";FNpower(FNplus(FNpower(9, 624), 2), 1872)
       30 PRINT "Time = ";(TIME - start%) / 100;"s"
       40 END
       50 DEF FND(n%)
       60   REPEAT 
       70     n% = (n% DIV 10) + (n% MOD 10)
       80   UNTIL n% < 10
       90   =n%
      100 DEF FNplus(a%, b%)=FND(FND(a%) + FND(b%))
      110 DEF FNmul(a%, b%)=FND(FND(a%) * FND(b%))
      120 DEF FNpower(a%, n%)
      130   IF n% = 1 THEN =FND(a%)
      135   IF n% MOD 2 = 0 THEN =FND(FNpower(a%, n% DIV 2) ^ 2)
      140   =FND(FND(a%) * FNpower(a%, n% - 1))    
    
    >RUN
    checksum = 1
    Time = 0.57s
    

    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.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: