58875674da
* include solution for problem 57 * fix line to long errors * update filenames and code to comply with new regulations * more descriptive local variables |
||
---|---|---|
.. | ||
problem_001 | ||
problem_002 | ||
problem_003 | ||
problem_004 | ||
problem_005 | ||
problem_006 | ||
problem_007 | ||
problem_008 | ||
problem_009 | ||
problem_010 | ||
problem_011 | ||
problem_012 | ||
problem_013 | ||
problem_014 | ||
problem_015 | ||
problem_016 | ||
problem_017 | ||
problem_018 | ||
problem_019 | ||
problem_020 | ||
problem_021 | ||
problem_022 | ||
problem_023 | ||
problem_024 | ||
problem_025 | ||
problem_026 | ||
problem_027 | ||
problem_028 | ||
problem_029 | ||
problem_030 | ||
problem_031 | ||
problem_032 | ||
problem_033 | ||
problem_034 | ||
problem_035 | ||
problem_036 | ||
problem_037 | ||
problem_039 | ||
problem_040 | ||
problem_041 | ||
problem_042 | ||
problem_043 | ||
problem_044 | ||
problem_045 | ||
problem_046 | ||
problem_047 | ||
problem_048 | ||
problem_049 | ||
problem_051 | ||
problem_052 | ||
problem_053 | ||
problem_054 | ||
problem_055 | ||
problem_056 | ||
problem_057 | ||
problem_062 | ||
problem_063 | ||
problem_067 | ||
problem_069 | ||
problem_071 | ||
problem_072 | ||
problem_074 | ||
problem_075 | ||
problem_076 | ||
problem_080 | ||
problem_091 | ||
problem_097 | ||
problem_099 | ||
problem_112 | ||
problem_113 | ||
problem_119 | ||
problem_120 | ||
problem_125 | ||
problem_173 | ||
problem_174 | ||
problem_191 | ||
problem_234 | ||
problem_551 | ||
__init__.py | ||
project_euler_answers.json | ||
README.md | ||
validate_solutions.py |
Project Euler
Problems are taken from https://projecteuler.net/.
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Project Euler is ideal for mathematicians who are learning to code.
The solutions will be checked by our automated testing on Travis CI with the help of this script. The efficiency of your code is also checked. You can view the top 10 slowest solutions on Travis CI logs and open a pull request to improve those solutions.
Solution Guidelines
Welcome to TheAlgorithms/Python! Before reading the solution guidelines, make sure you read the whole Contributing Guidelines as it won't be repeated in here. If you have any doubt on the guidelines, please feel free to state it clearly in an issue or ask the community in Gitter. You can use the template we have provided below as your starting point but be sure to read the Coding Style part first.
Coding Style
-
Please maintain consistency in project directory and solution file names. Keep the following points in mind:
- Create a new directory only for the problems which do not exist yet.
- If you create a new directory, please create an empty
__init__.py
file inside it as well. - Please name the project directory as
problem_<problem_number>
whereproblem_number
should be filled with 0s so as to occupy 3 digits. Example:problem_001
,problem_002
,problem_067
,problem_145
, and so on.
-
Please provide a link to the problem and other references, if used, in the module-level docstring.
-
All imports should come after the module-level docstring.
-
You can have as many helper functions as you want but there should be one main function called
solution
which should satisfy the conditions as stated below:- It should contain positional argument(s) whose default value is the question input. Example: Please take a look at problem 1 where the question is to Find the sum of all the multiples of 3 or 5 below 1000. In this case the main solution function will be
solution(limit: int = 1000)
. - When the
solution
function is called without any arguments like so:solution()
, it should return the answer to the problem.
- It should contain positional argument(s) whose default value is the question input. Example: Please take a look at problem 1 where the question is to Find the sum of all the multiples of 3 or 5 below 1000. In this case the main solution function will be
-
Every function, which includes all the helper functions, if any, and the main solution function, should have
doctest
in the function docstring along with a brief statement mentioning what the function is about.- There should not be a
doctest
for testing the answer as that is done by our Travis CI build using this script. Keeping in mind the above example of problem 1:
def solution(limit: int = 1000): """ A brief statement mentioning what the function is about. You can have a detailed explanation about the solution method in the module-level docstring. >>> solution(1) ... >>> solution(16) ... >>> solution(100) ... """
- There should not be a
Solution Template
You can use the below template as your starting point but please read the Coding Style first to understand how the template works.
Please change the name of the helper functions accordingly, change the parameter names with a descriptive one, replace the content within [square brackets]
(including the brackets) with the appropriate content.
"""
Project Euler Problem [problem number]: [link to the original problem]
... [Entire problem statement] ...
... [Solution explanation - Optional] ...
References [Optional]:
- [Wikipedia link to the topic]
- [Stackoverflow link]
...
"""
import module1
import module2
...
def helper1(arg1: [type hint], arg2: [type hint], ...) -> [Return type hint]:
"""
A brief statement explaining what the function is about.
... A more elaborate description ... [Optional]
...
[Doctest]
...
"""
...
# calculations
...
return
# You can have multiple helper functions but the solution function should be
# after all the helper functions ...
def solution(arg1: [type hint], arg2: [type hint], ...) -> [Return type hint]:
"""
A brief statement mentioning what the function is about.
You can have a detailed explanation about the solution in the
module-level docstring.
...
[Doctest as mentioned above]
...
"""
...
# calculations
...
return answer
if __name__ == "__main__":
print(f"{solution() = }")