Python/project_euler
Maxim Smolskiy a0b0f414ae
Add Project Euler problem 116 solution 1 (#6305)
* Add solution

* updating DIRECTORY.md

* Fix pre-commit

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-09-24 18:04:00 +01:00
..
problem_001 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_002 Fix style of the first ten solutions for Project Euler (#3242) 2020-10-25 08:53:16 +05:30
problem_003 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_004 Fix style of the first ten solutions for Project Euler (#3242) 2020-10-25 08:53:16 +05:30
problem_005 chore: rename gcd to greatest_common_divisor (#6265) 2022-07-24 21:33:10 +05:30
problem_006 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_007 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_008 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_009 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_010 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_011 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_012 Improve Project Euler problem 012 solution 2 (#5760) 2021-11-03 21:32:10 +01:00
problem_013 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_014 Improve Project Euler problem 014 solution 2 (#5744) 2021-11-04 17:01:21 +01:00
problem_015 Fix factorial issues (#5496) 2021-10-21 15:06:32 +08:00
problem_016 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_017 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_018 Pyupgrade to python3.8 (#3616) 2020-10-21 12:46:14 +02:00
problem_019 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_020 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_021 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_022 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_023 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_024 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_025 pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 (#6245) 2022-07-11 10:19:52 +02:00
problem_026 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_027 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_028 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_029 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_030 perf: improve Project Euler problem 030 solution 1 (#6267) 2022-07-25 22:11:12 +05:30
problem_031 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_032 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_033 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_034 Improve Project Euler problem 034 solution 1 (#5165) 2021-10-25 16:03:22 +08:00
problem_035 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_036 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_037 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_038 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_039 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_040 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_041 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_042 Pyupgrade to python3.8 (#3616) 2020-10-21 12:46:14 +02:00
problem_043 Improve Project Euler problem 043 solution 1 (#5772) 2021-11-05 20:44:24 +01:00
problem_044 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_045 fixed typo for codespell (#5753) 2021-11-02 22:17:57 +01:00
problem_046 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_047 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_048 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_049 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_050 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_051 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_052 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_053 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_054 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_055 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_056 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_057 Project Euler 57 - Square root convergents (#3259) 2020-10-16 21:17:35 +05:30
problem_058 Unify O(sqrt(N)) is_prime functions under project_euler (#6258) 2022-09-14 09:40:04 +01:00
problem_059 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_062 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_063 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_064 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_065 Add Project Euler 65 Solution (#3035) 2020-10-24 07:55:15 +05:30
problem_067 Improve code on f-strings and brevity (#6126) 2022-05-13 20:51:44 +08:00
problem_068 Add Project Euler 68 Solution (#5552) 2022-05-27 03:24:23 +08:00
problem_069 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_070 Improve Project Euler problem 070 solution 1 (#5166) 2021-10-30 21:36:12 +02:00
problem_071 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_072 Improve solution (#5705) 2021-10-31 11:37:46 +01:00
problem_074 Improve Project Euler problem 074 solution 2 (#5803) 2022-05-12 11:48:04 +08:00
problem_075 Add solution for Project Euler problem 75. (#3129) 2020-10-16 16:00:45 +05:30
problem_076 Rename Project Euler directories and other dependent changes (#3300) 2020-10-15 12:43:28 +05:30
problem_077 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_078 Improve Project Euler problem 078 solution 1 (#5708) 2021-10-31 11:36:53 +01:00
problem_080 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_081 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_085 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_086 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_087 Added solution for Project Euler problem 87. (#3141) 2020-10-29 12:19:33 +05:30
problem_089 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_091 Add solution for Project Euler problem 91. (#3144) 2020-10-16 15:44:06 +05:30
problem_092 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_097 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_099 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_101 Get rid of the Union (#6246) 2022-07-11 13:11:17 +02:00
problem_102 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_104 Add sol for P104 Project Euler (#5257) 2022-05-02 22:12:18 +08:00
problem_107 pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 (#6245) 2022-07-11 10:19:52 +02:00
problem_109 Added solution for Project Euler problem 109 (#4080) 2021-03-06 18:59:52 +05:30
problem_112 Improve Project Euler problem 112 solution 1 (#4808) 2021-10-06 22:11:50 +08:00
problem_113 Add solution for Project Euler problem 113 (#3109) 2020-10-15 15:29:53 +05:30
problem_114 feat: add Project Euler problem 114 solution 1 (#6300) 2022-08-07 07:37:35 +05:30
problem_115 feat: add Project Euler problem 115 solution 1 (#6303) 2022-08-07 16:50:45 +05:30
problem_116 Add Project Euler problem 116 solution 1 (#6305) 2022-09-24 18:04:00 +01:00
problem_119 Pyupgrade to Python 3.9 (#4718) 2021-09-07 13:37:03 +02:00
problem_120 Add Project Euler 120 solution (#2887) 2020-10-06 08:41:15 +05:30
problem_121 feat: Add solution for Project Euler Problem 121 (#4261) 2021-03-20 11:29:48 +05:30
problem_123 pre-commit autoupdate: pyupgrade v2.34.0 -> v2.37.0 (#6245) 2022-07-11 10:19:52 +02:00
problem_125 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_129 Added solution for Project Euler problem 129. (#3113) 2020-11-21 08:22:26 +05:30
problem_135 Add solution for Project Euler problem 135 (#4035) 2020-12-19 11:46:15 +05:30
problem_144 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_145 perf: Project Euler problem 145 solution 1 (#6259) 2022-07-23 07:23:46 +05:30
problem_173 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_174 Add solution for Project Euler problem 174. (#3078) 2020-10-16 15:14:09 +05:30
problem_180 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_188 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_191 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_203 perf: improve Project Euler problem 203 solution 1 (#6279) 2022-08-06 19:34:24 +05:30
problem_205 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_206 Project Euler 206 Solution (#3829) 2020-11-02 23:24:20 +05:30
problem_207 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_234 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_301 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_493 Added solution for euler problem 493 (#5573) 2021-10-31 11:48:10 +01:00
problem_551 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_587 feat: add Project Euler problem 587 solution 1 (#6269) 2022-07-26 21:45:14 +05:30
problem_686 Fix some typos in solution 1 of euler 686 (#6112) 2022-05-12 11:28:45 +08:00
__init__.py Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
README.md Replace Travis CI mentions with GitHub actions (#5751) 2021-11-02 22:28:09 +01:00

Project Euler

Problems are taken from https://projecteuler.net/, the Project Euler. Problems are licensed under CC BY-NC-SA 4.0.

Project Euler is a series of challenging mathematical/computer programming problems that 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 GitHub Actions with the help of this script. The efficiency of your code is also checked. You can view the top 10 slowest solutions on GitHub Actions logs (under slowest 10 durations) 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 GitHub Actions 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() = }")