Python/project_euler
Dhruv 2d7e08ef83
Update README.md for Project Euler (#3256)
* Update README.md for Project Euler

* Add link to solution template

* Add newlines for better separation

* Add __name__ == __main__ block in template

* Apply suggestions from code review

Co-authored-by: John Law <johnlaw.po@gmail.com>

* Improve introduction part

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-10-15 09:47:19 +05:30
..
problem_01 Cleanup Project Euler Problem 01 (#2900) 2020-10-10 11:03:00 +05:30
problem_02 Hacktoberfest 2020: Apply style guidelines for Project Euler problem_02 (#2898) 2020-10-06 10:04:16 +05:30
problem_03 Hacktoberfest 2020: Add style improvements for Project Euler Problem 03 (#2917) 2020-10-06 20:24:39 +05:30
problem_04 Add style improvements to solutions for Project Euler Problem 04 (#2945) 2020-10-07 10:33:34 +05:30
problem_05 Add type hints and default args for Project Euler problem 5 (#2982) 2020-10-08 08:50:11 +05:30
problem_06 Add default arguments for Project Euler problem 6 (#2957) 2020-10-07 10:17:43 +05:30
problem_07 Add default args and type hints for problem 7 (#2973) 2020-10-08 07:57:47 +02:00
problem_08 Add style improvements to Project Euler problem 8 (#3001) 2020-10-08 09:21:17 +05:30
problem_09 Add style improvements to Project Euler problem 9 (#3046) 2020-10-08 16:51:32 +05:30
problem_10 Project Euler Problem 10: style improvements (#2924) 2020-10-06 17:48:07 +05:30
problem_11 Fix docstring for Euler problem 11, solution 1 (#3228) 2020-10-12 19:44:45 +05:30
problem_12 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
problem_13 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_14 [Project Euler] Added type hints and refactored the code for Problem 14 (#3047) 2020-10-09 08:33:23 +05:30
problem_15 [Project Euler] Fix code style for problems 15 and 34 (#3076) 2020-10-09 08:46:55 +05:30
problem_16 Coding style improvements for project_euler problem 45 & 16 (#3087) 2020-10-09 12:09:44 +05:30
problem_17 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_18 Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
problem_19 Fixes for issue "Fix the LGTM issues #1024" (#1034) 2019-07-18 19:05:14 +02:00
problem_20 Add type hints and default args for problem 20 (#2962) 2020-10-07 17:59:55 +08:00
problem_21 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_22 pyupgrade --py37-plus **/*.py (#1654) 2020-01-03 22:25:36 +08:00
problem_23 Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
problem_24 Added doctest and more explanation about Dijkstra execution. (#1014) 2019-07-17 01:09:53 +02:00
problem_25 Add typehints and default input for project_euler/problem_25 (#2901) 2020-10-07 09:27:25 +05:30
problem_26 Style Improvements for project_euler/problem_26 (#2958) 2020-10-08 08:52:24 +05:30
problem_27 Coding style with default argument for project_euler problem 27 (#3020) 2020-10-08 16:53:00 +05:30
problem_28 Update code style for Project Euler Problem 28 (#2976) 2020-10-07 18:35:06 +05:30
problem_29 Bring problem_29 solution in line with project style guidelines (#2949) 2020-10-07 08:33:03 +05:30
problem_30 Bring problem_30 solution in line with project style guidelines (#2896) 2020-10-06 08:21:39 +05:30
problem_31 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_32 Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
problem_33 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_34 [Project Euler] Fix code style for problems 15 and 34 (#3076) 2020-10-09 08:46:55 +05:30
problem_35 Coding style change for project_euler problem 36 and 35 (#3062) 2020-10-09 08:35:13 +05:30
problem_36 Coding style change for project_euler problem 36 and 35 (#3062) 2020-10-09 08:35:13 +05:30
problem_37 Add solution method for project_euler/problem_37 (#2998) 2020-10-08 09:27:14 +05:30
problem_39 Fix coding style for Project Euler problem 39 (#3023) 2020-10-09 08:13:54 +05:30
problem_40 pyupgrade --py37-plus **/*.py (#1654) 2020-01-03 22:25:36 +08:00
problem_41 [Project Euler] Fix code style in Problem 41 (#2992) 2020-10-08 13:57:07 +05:30
problem_42 Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
problem_43 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_44 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_45 Coding style improvements for project_euler problem 45 & 16 (#3087) 2020-10-09 12:09:44 +05:30
problem_46 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_47 Only one carriage return (#2155) 2020-06-25 19:15:30 +02:00
problem_48 Update sol1.py (#2455) 2020-09-20 21:33:26 +02:00
problem_49 Add a solution for Project Euler 49 (#2702) 2020-10-05 08:27:09 +05:30
problem_51 Add project euler problem 51 (#3018) 2020-10-12 22:40:29 +05:30
problem_52 Added doctest and more explanation about Dijkstra execution. (#1014) 2019-07-17 01:09:53 +02:00
problem_53 pyupgrade --py37-plus **/*.py (#1654) 2020-01-03 22:25:36 +08:00
problem_54 Add solution() for problem 54 of Project Euler (#2472) 2020-09-24 15:16:55 +02:00
problem_55 [Project Euler] Fix code style in Problem 55 (#2985) 2020-10-07 20:39:36 +05:30
problem_56 [Project Euler] Fix code style for problem 56 (#3050) 2020-10-08 19:07:09 +05:30
problem_62 Project Euler 62 Solution (#3029) 2020-10-15 09:13:39 +05:30
problem_63 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
problem_67 psf/black code formatting (#1277) 2019-10-05 10:14:13 +05:00
problem_69 Added solution to Project Euler 69 (#2934) 2020-10-11 23:38:30 +05:30
problem_71 Add Project Euler Problem 71: Fixes #2695 (#2785) 2020-10-08 19:55:23 +08:00
problem_72 Add a solution to Project Euler 72 (#2940) 2020-10-12 19:46:15 +05:30
problem_76 Address #2786 - Fix code style in Project Euler Problem 76 (#2978) 2020-10-07 19:08:02 +05:30
problem_80 Add Project Euler Problem 80 (#2885) 2020-10-10 17:06:25 +05:30
problem_97 Created problem_97 in project euler (#2476) 2020-09-25 11:52:19 +02:00
problem_99 Hacktoberfest 2020: Rename method for project_euler/problem_99 (#2981) 2020-10-07 20:46:11 +05:30
problem_112 Created problem_112.py in project_euler (#2532) 2020-10-03 16:38:56 +08:00
problem_119 Added solution for Project Euler problem 119 (#2931) 2020-10-10 23:29:02 +05:30
problem_120 Add Project Euler 120 solution (#2887) 2020-10-06 08:41:15 +05:30
problem_125 Added solution for Project Euler problem 125 (#3073) 2020-10-09 22:41:00 +05:30
problem_191 Add solution for Project Euler problem 191 (#2875) 2020-10-11 17:59:27 +05:30
problem_234 Fixes: #3163 - Add new solution for problem 234 (#3177) 2020-10-11 23:16:16 +05:30
problem_551 [Project Euler] Fix code style for multiple problems (#3094) 2020-10-10 21:23:17 +05:30
__init__.py Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
project_euler_answers.json Improve validate solutions script & fix pre-commit error (#3253) 2020-10-13 15:41:12 +05:30
README.md Update README.md for Project Euler (#3256) 2020-10-15 09:47:19 +05:30
validate_solutions.py Improve validate solutions script & fix pre-commit error (#3253) 2020-10-13 15:41:12 +05:30

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> 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.

  • 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.
  • 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)
        ...
        """
    

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() = }")