Total Complexity | 1 |
Total Lines | 42 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | """ |
||
2 | Project Euler Problem 16: Power Digit Sum |
||
3 | ========================================= |
||
4 | |||
5 | .. module:: solutions.problem16 |
||
6 | :synopsis: My solution to problem #16. |
||
7 | |||
8 | The source code for this problem can be |
||
9 | `found here <https://bitbucket.org/nekedome/project-euler/src/master/solutions/problem16.py>`_. |
||
10 | |||
11 | Problem Statement |
||
12 | ################# |
||
13 | |||
14 | :math:`2^{15} = 32768` and the sum of its digits is :math:`3 + 2 + 7 + 6 + 8 = 26`. |
||
15 | |||
16 | What is the sum of the digits of the number :math:`2^{1000}`? |
||
17 | |||
18 | Solution Discussion |
||
19 | ################### |
||
20 | |||
21 | Simply compute :math:`2^{1000}` using Python's arbitrary precision arithmetic and then compute the digital sum. |
||
|
|||
22 | |||
23 | Solution Implementation |
||
24 | ####################### |
||
25 | |||
26 | .. literalinclude:: ../../solutions/problem16.py |
||
27 | :language: python |
||
28 | :lines: 31- |
||
29 | """ |
||
30 | |||
31 | from lib.digital import digit_sum |
||
32 | |||
33 | |||
34 | def solve(): |
||
35 | """ Compute the answer to Project Euler's problem #16 """ |
||
36 | target = 2 ** 1000 |
||
37 | answer = digit_sum(target) |
||
38 | return answer |
||
39 | |||
40 | |||
41 | expected_answer = 1366 |
||
42 |
This check looks for lines that are too long. You can specify the maximum line length.