Euler Python Implementation
All problems are solved in type-hinted python3
Organization
All files share a common prefix with their problem number. Several of
the problems also draw on code from the lib
subfolder for those that
require similar tools and strategies.
Makefile
There are three main recipes in this Makefile
dependencies
This recipe installs all the required and test dependencies. See the Dependencies section for more info
test
This recipe runs tests in a single thread and performs benchmarks and style checks on them.
test_*
This recipe runs tests in multiple threads, using however many are
specified by the number after the _. For example, test_3
would
spawn three python processes. Because benchmark disables itself when
running in children processes, benchmark info is not available with this
recipe.
Tests
Prime Numbers
There is a single test for the prime number infrastructure. It has three components:
It checks that it correctly generates the first million primes in the correct order
It checks that is_prime() operates correctly for all numbers in that range, including all composites between them
It checks that the whole series takes <200ns/prime to compute
Generic Problems
For each problem it will check the answer against a known dictionary. If the problem is not in the "known slow" category (meaning that I generate the correct answer with a poor solution), it will run it as many times as the benchmark plugin wants. Otherwise it is run exactly once.
A test fails if it gets the wrong answer or if it takes more than 1 minute.
Dependencies
I try to keep the dependencies of this project as small as possible, except for test plugins. At the moment there are only two non-test dependencies:
u-msgpack-python
This serialization library encodes things in the MessagePack format. The reason it is not only for testing is that it allows me to read from a cache of prime numbers stored on disk. This is not required, and if you remove it (and the import) things would still run correctly.
sortedcontainers
This library provides a collection of sorted containers. At the time of writing this, the only one I use is SortedSet() for the prime number generator. If I were willing to remove the prime number cache this would not be needed. I could also implement my own if need be.
Environment Variables
NO_OPTIONAL_TESTS
If this variable is defined to something other than 0 or an empty string, the test suite will skip any tests which are not directly related to Project Euler problems. This value will default to the same value as ONLY_SLOW.
NO_SLOW
If this variable is defined to something other than 0 or an empty string, problems in the known_slow group will not be tested. This variable defaults to True on Termux systems. If both NO_SLOW and ONLY_SLOW are truthy, they will be ignored and a warning will be issued.
ONLY_SLOW
If this variable is defined to something other than 0 or an empty string, only problems in the known_slow group will be tested. If both NO_SLOW and ONLY_SLOW are truthy, they will be ignored and a warning will be issued.
Live Tests
To run these problems in your browser, click here!
Library Code
Problems Solved
- Python Implementation of Problem 1
- Python Implementation of Problem 2
- Python Implementation of Problem 3
- Python Implementation of Problem 4
- Python Implementation of Problem 5
- Python Implementation of Problem 6
- Python Implementation of Problem 7
- Python Implementation of Problem 8
- Python Implementation of Problem 9
- Python Implementation of Problem 10
- Python Implementation of Problem 11
- Python Implementation of Problem 12
- Python Implementation of Problem 13
- Python Implementation of Problem 14
- Python Implementation of Problem 15
- Python Implementation of Problem 16
- Python Implementation of Problem 17
- Python Implementation of Problem 18
- Python Implementation of Problem 19
- Python Implementation of Problem 20
- Python Implementation of Problem 21
- Python Implementation of Problem 22
- Python Implementation of Problem 23
- Python Implementation of Problem 24
- Python Implementation of Problem 25
- Python Implementation of Problem 26
- Python Implementation of Problem 27
- Python Implementation of Problem 28
- Python Implementation of Problem 29
- Python Implementation of Problem 30
- Python Implementation of Problem 31
- Python Implementation of Problem 32
- Python Implementation of Problem 33
- Python Implementation of Problem 34
- Python Implementation of Problem 35
- Python Implementation of Problem 36
- Python Implementation of Problem 37
- Python Implementation of Problem 38
- Python Implementation of Problem 39
- Python Implementation of Problem 40
- Python Implementation of Problem 41
- Python Implementation of Problem 42
- Python Implementation of Problem 43
- Python Implementation of Problem 44
- Python Implementation of Problem 45
- Python Implementation of Problem 46
- Python Implementation of Problem 47
- Python Implementation of Problem 48
- Python Implementation of Problem 49
- Python Implementation of Problem 50
- Python Implementation of Problem 51
- Python Implementation of Problem 52
- Python Implementation of Problem 53
- Python Implementation of Problem 54
- Python Implementation of Problem 55
- Python Implementation of Problem 56
- Python Implementation of Problem 57
- Python Implementation of Problem 58
- Python Implementation of Problem 59
- Python Implementation of Problem 60
- Python Implementation of Problem 63
- Python Implementation of Problem 67
- Python Implementation of Problem 69
- Python Implementation of Problem 70
- Python Implementation of Problem 71
- Python Implementation of Problem 72
- Python Implementation of Problem 73
- Python Implementation of Problem 74
- Python Implementation of Problem 76
- Python Implementation of Problem 77
- Python Implementation of Problem 79
- Python Implementation of Problem 81
- Python Implementation of Problem 85
- Python Implementation of Problem 87
- Python Implementation of Problem 89
- Python Implementation of Problem 92
- Python Implementation of Problem 97
- Python Implementation of Problem 99
- Python Implementation of Problem 118
- Python Implementation of Problem 123
- Python Implementation of Problem 134
- Python Implementation of Problem 145
- Python Implementation of Problem 187
- Python Implementation of Problem 206
- Python Implementation of Problem 357
- Python Implementation of Problem 836