Power digit sum


Fork me on GitHub
2014-09-11

Problem 016: Power digit sum

Description:

2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?


Solution:
v00000000000000000000000000000000000000000000000000000000000
v00000000000000000000000000000000000000000000000000000000000
v00000000000000000000000000000000000000000000000000000000000
v00000000000000000000000000000000000000000000000000000000000
v00000000000000000000000000000000000000000000000000000000000
v00000000000000000000000000000000000000000000000000000000001

> "0":::::00p01p02p03p04p05p v  // INIT
v  p64*8"}"p60*p62:6p61:"<"  <v p66-1g66                <
       >06g1-66p             0> 66g16g%66g16g/g"0"-+ 66g|
v      $#                            <                  .
>46g:!#^_ 1-46p 06g1-66p 076p > 66g!#^_  v              @
v61g66+"0"%+55:+g67*2-"0"g/g61 g66%g61g66<
>g%66g16g/p55+/76p 66g1-66p   ^
Start
??
Pause
Reset
Output:
Stack:   (0)

Explanation:

Here I implemented a long multiplication algorithm. Then I took the value 1 and doubled it 1000 times. The calculation of the digit sum was then easy.


Interpreter steps: 27 332 672
Execution time (BefunExec): 4.23s (6.46 MHz)
Program size: 60 x 14 (fully conform befunge-93)
Solution: 1366
Solved at: 2014-09-11



made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript