These are my solutions to the Project Euler problem set. The solutions are written in a mixture of Python and Cython.
- Install required packages. The exact command will vary per Linux distribution. The command given below is for Fedora.
python3-devel,gcc, andgcc-c++are required to compile the Cython modules in this project.python-unversioned-commandis optional, but it allows you to use thepythoncommand without having to typepython3.
sudo dnf install python3 python3-devel python-unversioned-command gcc gcc-c++- Get project source.
git clone https://github.com/davidscholberg/project_euler.git
cd project_euler- Create and enter python virtual environment.
python -m venv .venv
source .venv/bin/activate- Build and install the project package as an editable install.
- Note that this command will need to be run after every change to a cython file (
.pyx) in order for the change to take effect. This does not apply to changes to python files.
- Note that this command will need to be run after every change to a cython file (
pip install --editable .- Install commit hook to run the unit tests on commit.
./install_commit_hooksTo run the solution for a particular problem, pass the problem number to the solve script:
solve 24The solve script runs the solution and compares the computed answer against the correct answer, the list of which was obtained from luckytoilet/projecteuler-solutions.
Note that the solve script is automatically generated by setuptools as an entry point.
- project_euler/ - Main project package. All python/cython source files go in here.
- data/ - Input data for problems that have non-trivial input.
- solutions/ - Solution files, one per solution. Logic should be kept to a minimum here.
- util/ - Package where reusable logic resides. All code here should have unit tests.
- install_commit_hooks - Script to install unit test commit hook.
- test - Script that runs all unit tests.