Skip to content

Files

This branch is 19 commits behind TheAlgorithms/Python:master.

project_euler

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 16, 2022
Jan 12, 2025
Mar 13, 2024
Apr 22, 2024
Oct 9, 2023
Mar 13, 2024
Mar 13, 2024
Aug 25, 2024
Aug 25, 2024
Mar 13, 2024
Aug 25, 2024
Oct 12, 2022
Mar 13, 2024
Mar 13, 2024
Apr 22, 2024
Jan 30, 2022
Oct 15, 2020
Mar 13, 2024
Mar 28, 2024
Apr 22, 2024
Mar 13, 2024
Apr 22, 2024
Oct 12, 2022
Mar 13, 2024
Nov 25, 2024
Oct 13, 2022
Apr 22, 2024
Mar 18, 2025
Oct 12, 2022
Mar 13, 2024
Apr 22, 2024
Apr 22, 2024
Apr 2, 2024
Jul 2, 2024
Jul 2, 2024
Mar 13, 2024
Jul 2, 2024
Apr 22, 2024
Jul 2, 2024
Apr 22, 2024
Jul 2, 2024
Mar 13, 2024
Jul 2, 2024
Jul 2, 2024
Jul 2, 2024
Jul 2, 2024
Oct 22, 2024
Jan 30, 2022
Sep 14, 2022
Mar 13, 2024
Mar 13, 2024
Oct 15, 2022
Apr 22, 2024
Mar 13, 2024
Jul 2, 2024
Jan 16, 2024
Oct 16, 2020
Jul 2, 2024
Mar 13, 2024
Oct 15, 2022
Jul 2, 2024
Mar 1, 2023
Oct 13, 2022
Mar 13, 2024
May 26, 2023
Jan 30, 2022
Mar 13, 2024
Oct 15, 2020
Jul 2, 2024
Oct 24, 2022
Mar 13, 2024
Mar 15, 2023
Oct 15, 2020
Mar 13, 2024
Oct 31, 2021
Mar 13, 2024
Mar 13, 2024
Mar 13, 2024
Mar 2, 2023
Mar 13, 2024
Mar 13, 2024
Oct 29, 2020
Jul 2, 2024
Mar 13, 2024
Apr 2, 2024
Apr 1, 2023
Jul 2, 2024
Oct 11, 2021
Mar 14, 2023
Mar 13, 2024
Mar 13, 2024
Apr 22, 2024
Apr 2, 2024
Mar 1, 2023
Aug 29, 2023
Oct 3, 2022
Aug 7, 2022
Aug 7, 2022
Sep 24, 2022
Mar 2, 2023
Sep 7, 2021
Apr 22, 2024
Mar 20, 2021
Nov 25, 2024
Oct 16, 2022
Nov 21, 2020
May 26, 2023
Apr 22, 2024
Apr 22, 2024
Mar 20, 2024
Mar 13, 2024
Apr 22, 2024
Mar 13, 2024
Oct 15, 2023
Oct 13, 2022
Mar 13, 2024
Mar 13, 2024
Jan 30, 2022
Nov 2, 2020
Apr 2, 2024
Jan 30, 2022
Jan 30, 2022
Oct 7, 2023
Mar 13, 2024
Jul 26, 2022
May 12, 2022
Apr 1, 2023
Mar 26, 2023
Sep 28, 2020

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