Factorial digit sum


Fork me on GitHub
2014-09-14

Problem 020: Factorial digit sum

Description:

n! means n × (n - 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!


Solution:
v0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
v0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001
>"d">1-:!#v_:03p013p"~I"+23p>23g"d"%1+23g"d"/g"0"-03g*13g+:55+%68 v
    ^     $#               _^#!p32:-1g32p31/+55p/"d"g32+1%"d"g32+*<
          >"~I"+33p0>33g"d"%1+33g"d"/g"0"-+  33g:1-33p v
                 @._^#!                                <
Start
??
Pause
Reset
Output:
Stack:   (0)

Explanation:

The approach is similar to problem 16 - the main task was implementing a long multiplication algorithm in Befunge. Then, after 100! is calculated we only need to sum the individual digits.


Interpreter steps: 1 546 679
Execution time (BefunExec): 265ms (5.84 MHz)
Program size: 101 x 6
Solution: 648
Solved at: 2014-09-14



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