solutions.problem7.solve()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
"""
2
Project Euler Problem 7: 10001St Prime
3
======================================
4
5
.. module:: solutions.problem7
6
   :synopsis: My solution to problem #7.
7
8
The source code for this problem can be
9
`found here <https://bitbucket.org/nekedome/project-euler/src/master/solutions/problem7.py>`_.
10
11
Problem Statement
12
#################
13
14
By listing the first six prime numbers: :math:`2,3,5,7,11`, and :math:`13`, we can see that the :math:`6^{th}` prime is
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (119/100).

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

Loading history...
15
:math:`13`.
16
17
What is the :math:`10001^{st}` prime number?
18
19
Solution Discussion
20
###################
21
22
Iterate over primes using sieving techniques until we reach the :math:`10001^{st}` one.
23
24
Solution Implementation
25
#######################
26
27
.. literalinclude:: ../../solutions/problem7.py
28
   :language: python
29
   :lines: 32-
30
"""
31
32
from itertools import islice
33
34
from lib.sequence import Primes
35
36
37
def solve():
38
    """ Compute the answer to Project Euler's problem #7 """
39
    target = 10001
40
    primes = Primes(n_primes=target)
41
    answer = next(islice(primes, target - 1, target))  # skip ahead to the 10001^{st} prime
42
    return answer
43
44
45
expected_answer = 104743
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...
46