Skip to content

landsgevaer/euler.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

euler.py

Project Euler in Python

version MIT License

Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.

This repository contains a collection of hand-crafted solutions to these problems in the Python 3 programming language, using only built-in functions and modules from the Python Standard Library. There are no further dependencies.

⚠️ This repository contains spoilers. Please refrain from using it if you wish to solve the problems yourself.

The various solutions all contain a main() function that computes the solution, plus potentially a set of helper functions that performs general tasks. The latter are often imported and re-used in solutions to later problems. These may also be useful to you; for an overview of these, see the table under Execution / Usage.

Table of Contents

Installation

Assuming you have Python 3.x installed, simply clone the repository from a terminal, and you are ready to go:

git clone https://github.com/landsgevaer/euler.py

⚠️ The codebase was tested using Python 3.12 but should work on various earlier versions as well.

Execution / Usage

To run the main script, fire up a terminal window and run the following command:

python3 main.py

This will run all available solutions to solved problems, verify their correctness, measure their runtime, and show an overview of the results in the terminal. The results will also be written to a file results.md (you may specify a different filename by providing it as a command-line argument, like python3 main.py my_output.md).

⚠️ This script will also automatically update the overview of helper functions in this README.md file.

You may also run a single solution separately using a command like:

python3 solutions/problem0000.py

The problems are numbered according to the problem ID on the Problem Archives. Problem 0 refers to the problem posed when registering (note that the numbers in problem 0 are randomised for each visitor).

The following helper functions are provided in the various solutions:

Module Function Description
problem0002 generate_fibonacci() Generator of Fibonacci numbers.
problem0003 factorize_primes(n) Decompose a number into prime factors with their exponents.
problem0003 generate_primes() Generator of prime numbers.
problem0003 is_prime(number) Determine whether a number is prime.
problem0009 list_divisors(n) List all divisors of n.
problem0014 generate_collatz(n) Generator of Collatz sequence.
problem0017 speak_number(n, *, scale=0) Returns the English spoken form of a number (up to 10^21) as a string.
problem0031 count_partitions(n, *, allowed=None) Count how many ways an integer n can be partitioned into numbers from a set.
problem0040 generate_champernowne() Generator of champernowne constant decimals.

Contributing

Because this is a personal project to challenge myself to solve all problems in the Euler Project, no pull requests will be accepted. You are of course free to be inspired by this repository and improve on its solutions yourself. In case of questions or comments on the solutions, feel free to contact me (see the author details below).

Author

Dave R.M. Langers – @landsgevaerdave@langers.nl

License

"Project Euler in Python" is distributed under the MIT-license. See LICENSE for more details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages