| Total Complexity | 1 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Project Euler Problem 20: Factorial Digit Sum |
||
| 3 | ============================================= |
||
| 4 | |||
| 5 | .. module:: solutions.problem20 |
||
| 6 | :synopsis: My solution to problem #20. |
||
| 7 | |||
| 8 | The source code for this problem can be |
||
| 9 | `found here <https://bitbucket.org/nekedome/project-euler/src/master/solutions/problem20.py>`_. |
||
| 10 | |||
| 11 | Problem Statement |
||
| 12 | ################# |
||
| 13 | |||
| 14 | :math:`n!` means :math:`n \\times (n - 1) \\times \\dots \\times 3 \\times 2 \\times 1` |
||
| 15 | |||
| 16 | | For example, :math:`10! = 10 \\times 9 \\times \\dots \\times 3 \\times 2 \\times 1 = 3628800`, |
||
| 17 | | and the sum of the digits in the number :math:`10!` is :math:`3 + 6 + 2 + 8 + 8 + 0 + 0 = 27`. |
||
| 18 | |||
| 19 | Find the sum of the digits in the number :math:`100!` |
||
| 20 | |||
| 21 | Solution Discussion |
||
| 22 | ################### |
||
| 23 | |||
| 24 | Build the value of :math:`100!` using Python's arbitrary precision arithmetic and then perform a decimal digit sum on |
||
|
|
|||
| 25 | that result. |
||
| 26 | |||
| 27 | Solution Implementation |
||
| 28 | ####################### |
||
| 29 | |||
| 30 | .. literalinclude:: ../../solutions/problem20.py |
||
| 31 | :language: python |
||
| 32 | :lines: 35- |
||
| 33 | """ |
||
| 34 | |||
| 35 | from lib.digital import digit_sum |
||
| 36 | from lib.sequence import Factorials |
||
| 37 | |||
| 38 | |||
| 39 | def solve(): |
||
| 40 | """ Compute the answer to Project Euler's problem #20 """ |
||
| 41 | target = 100 |
||
| 42 | factorials = Factorials() |
||
| 43 | x = factorials[target] |
||
| 44 | answer = digit_sum(x) |
||
| 45 | return answer |
||
| 46 | |||
| 47 | |||
| 48 | expected_answer = 648 |
||
| 49 |
This check looks for lines that are too long. You can specify the maximum line length.