Total Complexity | 1 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Changes | 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 |
||
|
|||
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 |
||
46 |
This check looks for lines that are too long. You can specify the maximum line length.