| Total Complexity | 4 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Project Euler Problem 1: Multiples of 3 and 5 |
||
| 3 | ============================================= |
||
| 4 | |||
| 5 | .. module:: solutions.problem1 |
||
| 6 | :synopsis: My solution to problem #1. |
||
| 7 | |||
| 8 | The source code for this problem can be |
||
| 9 | `found here <https://bitbucket.org/nekedome/project-euler/src/master/solutions/problem1.py>`_. |
||
| 10 | |||
| 11 | Problem Statement |
||
| 12 | ################# |
||
| 13 | |||
| 14 | If we list all the natural numbers below :math:`10` that are multiples of :math:`3` or :math:`5`, we get :math:`3, 5, 6` |
||
|
|
|||
| 15 | and :math:`9`. The sum of these multiples is :math:`23`. |
||
| 16 | |||
| 17 | Find the sum of all the multiples of :math:`3` or :math:`5` below :math:`1000`. |
||
| 18 | |||
| 19 | Solution Discussion |
||
| 20 | ################### |
||
| 21 | |||
| 22 | Nothing sophisticated here, explicitly perform the computation. |
||
| 23 | |||
| 24 | Solution Implementation |
||
| 25 | ####################### |
||
| 26 | |||
| 27 | .. literalinclude:: ../../solutions/problem1.py |
||
| 28 | :language: python |
||
| 29 | :lines: 33- |
||
| 30 | """ |
||
| 31 | |||
| 32 | |||
| 33 | def solve(): |
||
| 34 | """ Compute the answer to Project Euler's problem #1 """ |
||
| 35 | num_range = range(1, 1000) |
||
| 36 | valid = lambda n: n % 3 == 0 or n % 5 == 0 # number must be a multiple of 3 OR 5 |
||
| 37 | numbers = [i for i in num_range if valid(i)] |
||
| 38 | answer = sum(numbers) |
||
| 39 | return answer |
||
| 40 | |||
| 41 | |||
| 42 | expected_answer = 233168 |
||
| 43 |
This check looks for lines that are too long. You can specify the maximum line length.