solutions.problem16.solve()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 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.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (111/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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
0 ignored issues
show
Coding Style Naming introduced by
The name expected_answer does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
42