Python/project_euler
Maxim Smolskiy e3fa014a5a
Fix ruff (#11527)
* updating DIRECTORY.md

* Fix ruff

* Fix

* Fix

* Fix

* Revert "Fix"

This reverts commit 5bc3bf3422.

* find_max.py: noqa: PLR1730

---------

Co-authored-by: MaximSmolskiy <MaximSmolskiy@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2024-08-25 17:33:11 +02:00
..
problem_001 Misc fixes across multiple algorithms (#6912) 2022-10-16 10:55:38 +05:30
problem_002 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_003 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_004 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_005 Removed redundant greatest_common_divisor code (#9358) 2023-10-09 14:19:12 +02:00
problem_006 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_007 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_008 Fix ruff (#11527) 2024-08-25 17:33:11 +02:00
problem_009 Fix ruff (#11527) 2024-08-25 17:33:11 +02:00
problem_010 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_011 Fix ruff (#11527) 2024-08-25 17:33:11 +02:00
problem_012
problem_013 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_014 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_015 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_016
problem_017
problem_018 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_019 Enable ruff PLR5501 rule (#11332) 2024-03-28 18:25:41 +01:00
problem_020 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_021 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_022 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_023
problem_024 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_025 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_026
problem_027 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_028 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_029
problem_030 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_031 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_032 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_033 Enable ruff SIM102 rule (#11341) 2024-04-02 03:27:56 +02:00
problem_034 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_035 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_036 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_037 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_038 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_039 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_040 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_041 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_042 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_043 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_044 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_045 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_046 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_047 [pre-commit.ci] pre-commit autoupdate (#11417) 2024-05-27 21:56:48 -04:00
problem_048
problem_049
problem_050 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_051 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_052
problem_053 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_054 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_055 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_056 Use compiled black as the pre-commit formatter (#11247) 2024-01-16 09:39:54 +01:00
problem_057
problem_058 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_059 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_062
problem_063 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_064
problem_065
problem_067 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_068
problem_069 The black formatter is no longer beta (#5960) 2022-01-30 20:29:54 +01:00
problem_070 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_071
problem_072 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_073
problem_074 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_075
problem_076
problem_077 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_078
problem_079 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_080 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_081 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_082
problem_085 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_086 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_087
problem_089 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_091 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_092 Enable ruff PGH003 rule (#11345) 2024-04-02 21:29:34 +02:00
problem_094
problem_097 [pre-commit.ci] pre-commit autoupdate (#11473) 2024-07-02 07:02:29 +02:00
problem_099 [mypy] fix type annotations for all Project Euler problems (#4747) 2021-10-12 00:33:44 +08:00
problem_100
problem_101 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_102 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_104 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_107 Enable ruff SIM102 rule (#11341) 2024-04-02 03:27:56 +02:00
problem_109 Make some ruff fixes (#8154) 2023-03-01 17:23:33 +01:00
problem_112
problem_113
problem_114
problem_115
problem_116
problem_117
problem_119
problem_120 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_121
problem_123 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_125
problem_129
problem_131
problem_135 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_144 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_145 Enable ruff ARG001 rule (#11321) 2024-03-20 15:00:17 +01:00
problem_173 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_174 Enable ruff RUF002 rule (#11377) 2024-04-22 21:51:47 +02:00
problem_180 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_187
problem_188
problem_191 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_203 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_205
problem_206
problem_207 Enable ruff SIM102 rule (#11341) 2024-04-02 03:27:56 +02:00
problem_234
problem_301
problem_493
problem_551 [pre-commit.ci] pre-commit autoupdate (#11322) 2024-03-13 07:52:41 +01:00
problem_587
problem_686
problem_800
__init__.py
README.md

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