Project Euler¶
A collection of my solutions to Project Euler challenges. All code is my own work and I have solved all problems before reviewing others’ approaches. On occasion, I have incorporated superior ideas into these solutions when I have come across something particularly novel/clever.
Overview¶
According to its website, Project Euler was created by Colin Hughes (a.k.a. euler) in October 2001 as a sub-section on http://mathschallenge.net
Project Euler is an ever-growing collection of computational problems with a particular mathematical bent, contributed by community members.
Each problem has a numeric answer, which can be submitted to the website to check its correctness. Doing so provides access to a forum discussing others’ answers to that same problem.
All problems have been designed to adhere to the “one-minute rule”. That is, there is an efficient algorithm to solve each and every problem that will run on a modestly powerful computer in less than one minute. Distributed computing is not required and your choice of language is irrelevant - if you have found an efficient solution ☺
Happy coding!
Usage Instructions¶
This project contains a collection of solutions to Project Euler problems and a series of useful components:
- a library of mathematical functions (and corresponding unit testing)
- an API for solutions to conform to
- a command-line application providing high-level functions (see below)
This is a Python 3.6 project and utilises a number of extra dependencies as specified in requirements.txt. You can manually configure a corresponding Python environment, or alternatively deploy a Python virtual environment and use pip to install all necessary dependencies.
For example, in Linux, the following steps will deploy a virtual environment with the required dependencies:
python3 -m venv env # create a virtual environment called env
source env/bin/activate # enter the virtual environment
pip install -r requirements.txt # install all dependencies
You can find detailed usage instructions in the synopsis for this project, however, here is a short cheat sheet.
To begin work on a new problem (identified by PROBLEM_NUMBER
) use the following:
python main.py start PROBLEM_NUMBER
The start
function will scrape the Project Euler website and create boilerplate files to hold your solution
implementation and its associated documentation describing that solution. The problem description will be captured in
this boiler-plating and any associated datafiles that are linked from the problem on the Project Euler website will also
be downloaded into the data/problems
directory.
Each solution is contained in a Python module in the solutions
directory and exposes two key elements:
- The
solve()
function which computes and returns the putative answer - The
expected_answer
member which contains the expected answer if it is known (None
otherwise)
To compute your solution to PROBLEM_NUMBER
use the following:
python main.py solve PROBLEM_NUMBER
Finally, you may want to compute and validate all solutions:
python main.py validate
My Solutions¶
The following tables provide links to my solutions where they exist. The table indicates which problems I’ve solved, which ones compute the correct answer and their run-times in seconds.
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
1 - 10 | 0.00 | 0.00 | 0.07 | 0.10 | 0.02 | 0.00 | 0.02 | 0.00 | 0.08 | 0.48 |
11 - 20 | 0.00 | 0.09 | 0.00 | 2.88 | 0.00 | 0.00 | 0.00 | 0.00 | 0.01 | 0.00 |
21 - 30 | 0.02 | 0.04 | 0.57 | 0.03 | 0.01 | 0.01 | 0.11 | 0.36 | 0.01 | 0.04 |
31 - 40 | 0.02 | 1.87 | 0.03 | 0.06 | 0.51 | 0.69 | 0.19 | 0.09 | 0.19 | 0.07 |
41 - 50 | 0.09 | 0.02 | 4.19 | 0.16 | 0.08 | 0.20 | 0.05 | 0.00 | 0.01 | 0.06 |
51 - 60 | ||||||||||
61 - 70 | ||||||||||
71 - 80 | ||||||||||
81 - 90 | ||||||||||
91 - 100 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
101 - 110 | ||||||||||
111 - 120 | ||||||||||
121 - 130 | ||||||||||
131 - 140 | ||||||||||
141 - 150 | ||||||||||
151 - 160 | ||||||||||
161 - 170 | ||||||||||
171 - 180 | ||||||||||
181 - 190 | ||||||||||
191 - 200 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
201 - 210 | ||||||||||
211 - 220 | ||||||||||
221 - 230 | ||||||||||
231 - 240 | ||||||||||
241 - 250 | ||||||||||
251 - 260 | ||||||||||
261 - 270 | ||||||||||
271 - 280 | ||||||||||
281 - 290 | ||||||||||
291 - 300 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
301 - 310 | ||||||||||
311 - 320 | ||||||||||
321 - 330 | ||||||||||
331 - 340 | ||||||||||
341 - 350 | ||||||||||
351 - 360 | ||||||||||
361 - 370 | ||||||||||
371 - 380 | ||||||||||
381 - 390 | ||||||||||
391 - 400 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
401 - 410 | ||||||||||
411 - 420 | ||||||||||
421 - 430 | ||||||||||
431 - 440 | ||||||||||
441 - 450 | ||||||||||
451 - 460 | ||||||||||
461 - 470 | ||||||||||
471 - 480 | ||||||||||
481 - 490 | ||||||||||
491 - 500 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
501 - 510 | ||||||||||
511 - 520 | ||||||||||
521 - 530 | ||||||||||
531 - 540 | ||||||||||
541 - 550 | ||||||||||
551 - 560 | ||||||||||
561 - 570 | ||||||||||
571 - 580 | ||||||||||
581 - 590 | ||||||||||
591 - 600 |
*1 | *2 | *3 | *4 | *5 | *6 | *7 | *8 | *9 | *0 | |
601 - 610 | ||||||||||
611 - 620 | ||||||||||
621 - 630 | ||||||||||
631 - 640 | ||||||||||
641 - 650 | ||||||||||
651 - 660 | ||||||||||
661 - 670 | ||||||||||
671 - 680 | ||||||||||
681 - 690 | ||||||||||
691 - 700 |
Note
these run-times are measured on whatever build system is employed by Read the Docs running the standard Python 3.6 interpreter, CPython. All solutions are single-threaded.
Solution Run-time Legend
- the answer was computed correctly
- the answer was computed, but was incorrect
- a solution to this problem does not yet exist
Code Layout¶
This project consists of the following Python modules/packages:
This project is hosted on BitBucket.