From 134fd4715f4a1cb55cd9ce08c7a466de2ec3a591 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 13 Oct 2020 17:28:49 +0530 Subject: [PATCH 1/6] Update README.md for Project Euler --- project_euler/README.md | 97 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/project_euler/README.md b/project_euler/README.md index f80d58ea0038..d6a43a50b34a 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -1,4 +1,4 @@ -# ProjectEuler +# Project Euler Problems are taken from https://projecteuler.net/. @@ -9,3 +9,98 @@ Here the efficiency of your code is also checked. I've tried to provide all the best possible solutions. For description of the problem statements, kindly visit https://projecteuler.net/show=all + + +## Solution Guidelines + +Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before reading the solution guidelines, make sure you read the whole [contributing guidelines](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md) 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](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). + +### 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 does not exists yet. + * If you create a new directory, please create an empty `__init__.py` file as well. + * Please name the project directory as `problem_` where `problem_number` should be filled with 0s so as to occupy 3 decimal places. 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](https://projecteuler.net/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. +* 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](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py). Keeping in mind the above example of [problem 1](https://projecteuler.net/problem=1): + ```python + 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) + ... + """ + ``` + +#### Project Euler Solution Template + +You can use the below template as your starting point but please read the [coding style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#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. + +```python +""" +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. + + ... + [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 +``` \ No newline at end of file From 5d11384564281aac9b0dec51a35a312000b72e62 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Tue, 13 Oct 2020 17:34:11 +0530 Subject: [PATCH 2/6] Add link to solution template --- project_euler/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_euler/README.md b/project_euler/README.md index d6a43a50b34a..a414ad40697b 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -13,7 +13,7 @@ For description of the problem statements, kindly visit https://projecteuler.net ## Solution Guidelines -Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before reading the solution guidelines, make sure you read the whole [contributing guidelines](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md) 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](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). +Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before reading the solution guidelines, make sure you read the whole [contributing guidelines](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md) 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](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). You can use the [template](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#solution-template) we have provided below as your starting point but be sure to read the [coding style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#coding-style) part first. ### Coding Style @@ -44,7 +44,7 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo """ ``` -#### Project Euler Solution Template +### Solution Template You can use the below template as your starting point but please read the [coding style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#coding-style) first to understand how the template works. From c408b2f0c039247160cd4a5c7e83d3046c0fa1a8 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 14 Oct 2020 07:52:09 +0530 Subject: [PATCH 3/6] Add newlines for better separation --- project_euler/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/project_euler/README.md b/project_euler/README.md index a414ad40697b..714b27b672a3 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -21,13 +21,18 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo * Create a new directory only for the problems which does not exists yet. * If you create a new directory, please create an empty `__init__.py` file as well. * Please name the project directory as `problem_` where `problem_number` should be filled with 0s so as to occupy 3 decimal places. 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](https://projecteuler.net/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. + * 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](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py). Keeping in mind the above example of [problem 1](https://projecteuler.net/problem=1): + ```python def solution(limit: int = 1000): """ From f968c86372c29d35449b4423b73f8db0b3357ef9 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 14 Oct 2020 17:08:36 +0530 Subject: [PATCH 4/6] Add __name__ == __main__ block in template --- project_euler/README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/project_euler/README.md b/project_euler/README.md index 714b27b672a3..2f2b70d99503 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -88,9 +88,11 @@ def helper1(arg1: [type hint], arg2: [type hint], ...) -> [Return type hint]: 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. @@ -108,4 +110,8 @@ def solution(arg1: [type hint], arg2: [type hint], ...) -> [Return type hint]: ... return answer -``` \ No newline at end of file + + +if __name__ == "__main__": + print(f"{solution() = }") +``` From c16e3772264e3e8b23a0f36073f1f5c670d3f7b4 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Thu, 15 Oct 2020 09:19:05 +0530 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: John Law --- project_euler/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/project_euler/README.md b/project_euler/README.md index 2f2b70d99503..3f0903ba72f1 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -13,14 +13,14 @@ For description of the problem statements, kindly visit https://projecteuler.net ## Solution Guidelines -Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before reading the solution guidelines, make sure you read the whole [contributing guidelines](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md) 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](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). You can use the [template](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#solution-template) we have provided below as your starting point but be sure to read the [coding style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#coding-style) part first. +Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Before reading the solution guidelines, make sure you read the whole [Contributing Guidelines](https://github.com/TheAlgorithms/Python/blob/master/CONTRIBUTING.md) 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](https://github.com/TheAlgorithms/Python/issues/new) or ask the community in [Gitter](https://gitter.im/TheAlgorithms). You can use the [template](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#solution-template) we have provided below as your starting point but be sure to read the [Coding Style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#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 does not exists yet. - * If you create a new directory, please create an empty `__init__.py` file as well. - * Please name the project directory as `problem_` where `problem_number` should be filled with 0s so as to occupy 3 decimal places. Example: `problem_001`, `problem_002`, `problem_067`, `problem_145`, and so on. + * 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_` where `problem_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. @@ -30,7 +30,7 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo * It should contain positional argument(s) whose default value is the question input. Example: Please take a look at [problem 1](https://projecteuler.net/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. -* 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. +* 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](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py). Keeping in mind the above example of [problem 1](https://projecteuler.net/problem=1): ```python @@ -51,7 +51,7 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo ### Solution Template -You can use the below template as your starting point but please read the [coding style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#coding-style) first to understand how the template works. +You can use the below template as your starting point but please read the [Coding Style](https://github.com/TheAlgorithms/Python/blob/master/project_euler/README.md#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. From 393b5cb4427b31918820cdd250d44da3c6885ab4 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 15 Oct 2020 09:38:59 +0530 Subject: [PATCH 6/6] Improve introduction part --- project_euler/README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/project_euler/README.md b/project_euler/README.md index 3f0903ba72f1..934e541cc067 100644 --- a/project_euler/README.md +++ b/project_euler/README.md @@ -5,10 +5,7 @@ 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. -Here the efficiency of your code is also checked. -I've tried to provide all the best possible solutions. - -For description of the problem statements, kindly visit https://projecteuler.net/show=all +The solutions will be checked by our [automated testing on Travis CI](https://travis-ci.com/github/TheAlgorithms/Python/pull_requests) with the help of [this script](https://github.com/TheAlgorithms/Python/blob/master/project_euler/validate_solutions.py). 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 @@ -37,6 +34,7 @@ Welcome to [TheAlgorithms/Python](https://github.com/TheAlgorithms/Python)! Befo 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. @@ -77,6 +75,8 @@ 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] ... @@ -96,6 +96,7 @@ def helper1(arg1: [type hint], arg2: [type hint], ...) -> [Return type hint]: 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.