solutions.problem29   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A solve() 0 8 2
1
"""
2
Project Euler Problem 29: Distinct Powers
3
=========================================
4
5
.. module:: solutions.problem29
6
   :synopsis: My solution to problem #29.
7
8
The source code for this problem can be
9
`found here <https://bitbucket.org/nekedome/project-euler/src/master/solutions/problem29.py>`_.
10
11
Problem Statement
12
#################
13
14
Consider all integer combinations of :math:`a^b` for :math:`2 \\le a \\le 5` and :math:`2 \\le b \\le 5`:
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (105/100).

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

Loading history...
15
16
.. math::
17
18
    &2^2=4,  &2^3=8,   &2^4=16,  &2^5=32 \\\\
19
    &3^2=9,  &3^3=27,  &3^4=81,  &3^5=243 \\\\
20
    &4^2=16, &4^3=64,  &4^4=256, &4^5=1024 \\\\
21
    &5^2=25, &5^3=125, &5^4=625, &5^5=3125 \\\\
22
23
If they are then placed in numerical order, with any repeats removed, we get the following sequence of :math:`15`
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (113/100).

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

Loading history...
24
distinct terms:
25
26
.. math::
27
28
    4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
29
30
How many distinct terms are in the sequence generated by :math:`a^b` for :math:`2 \\le a \\le 100` and
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (102/100).

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

Loading history...
31
:math:`2 \\le b \\le 100`?
32
33
Solution Discussion
34
###################
35
36
Nothing sophisticated here, explicitly perform the computation.
37
38
Solution Implementation
39
#######################
40
41
.. literalinclude:: ../../solutions/problem29.py
42
   :language: python
43
   :lines: 46-
44
"""
45
46
from itertools import product
47
48
49
def solve():
50
    """ Compute the answer to Project Euler's problem #29 """
51
    upper_bound = 100
52
    terms = set()
53
    for a, b in product(range(2, upper_bound + 1), repeat=2):
0 ignored issues
show
Coding Style Naming introduced by
The name a does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
Coding Style Naming introduced by
The name b does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
54
        terms.add(a ** b)
55
    answer = len(terms)
56
    return answer
57
58
59
expected_answer = 9183
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...
60