project-youler
A command line tool for managing your Project Euler solutions (if they're written in Python).
Features include:
- Stores all your confirmed answers in a local JSON file. If you refactor your solution, you can run the
checkcommand to make sure none of your solvers have broken. - Fetches the problem description from the Project Euler website and creates a template file for you to fill in with your solution.
- Shows an overview of how many problems you've solved and/or attempted.
- Really basic timing info for profiling your solutions.
This package doesn't contain any solutions itself (that would be uncool).
Setup
In the project where you've written your solutions, add this package as a dependency, and create an entry point for the click CLI returned by make_cli.
Example:
# src/my_euler/__main__.py
from pathlib import Path
from youler import EulerConfig, make_cli
from . import bonus, problems
cli = make_cli(
EulerConfig(
root=Path(__file__).parents[2],
problems=problems,
bonus=bonus,
answer_file="answers.json",
)
)
if __name__ == "__main__":
cli()
If you wire it up as a script, you can run euler from anywhere in the
project:
[project.scripts]
euler = "my_euler.__main__:cli"
Aside: make_cli returns an ordinary click.Group, so you can register extra commands of your own on it.
Configuration
| field | meaning |
|---|---|
root |
Root of your repository; answer_file is resolved against it. |
problems |
The imported package holding your numbered solvers. |
bonus |
The imported package holding your bonus solvers. Optional. |
answer_file |
Where confirmed answers are saved. Defaults to answers.json. |
Writing a solver
A solver is a module named pNNNN.py inside your problems package, exporting
solve_problem():
# src/my_euler/problems/p0001.py
"""
If we list all the natural numbers below 10 that are multiples of 3 or 5, we
get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
"""
def solve_problem() -> int:
return sum(n for n in range(1000) if n % 3 == 0 or n % 5 == 0)
(okay, there's one solution in this package)
euler create 1 creates that file for you, with the problem statement fetched
from the Project Euler website and formatted into the docstring.
An answer may be an int or a str, as far as I know.
Bonus problems
Spoiler warning
Project Euler has some mysterious bonus problems that unlock after unknown conditions. Personally, I've only seen two of them. I've managed to wedge them into this framework in a reasonably clean way, just specify an arbitrary string key and it'll create a bonus problem.
For example, if you create a file bonus/p18i.py, you can run it with euler run 18i and it'll work like other problems.
Details subject to change since I have no idea what other bonus problems lurk in the darkness.
Commands
[!NOTE] Most of these commands take arguments of the form
a-b, meaning problems a to b inclusive, the id of a bonus problem, and the special valueall, which means slightly different things to different commands.You can always pass
--helpfor more detail on a particular command.
create <n>: Createproblems/pNNNN.pyfor problem #n, prefilled with the problem statement from the Project Euler website.run <n>: Run the solver for problem #n. If there is already a saved answer, it'll be compared with it, if not, you'll be prompted whether you want to save it. (Submit it to PE first so you know it's right!)check <n>: Run the solver for problem #n and compare it against the saved answer, without prompting.check allcovers everything you've written or saved, which is nice for validating a refactor.time <n>: Run one problem several times and report the average time taken.status: Show which problems have been downloaded, solved, or neither.answers: Subcommands for manipulating the answer save file.show <n>: Show saved answers.delete <n>: Delete saved answers.
Development
I use uv, mypy and pytest, in a very typical setup.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file project_youler-0.0.1.tar.gz.
File metadata
- Download URL: project_youler-0.0.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4205921bf6a1ae358f377a6762887c0a756a38ab35d5652d0e7904fbae976b7b
|
|
| MD5 |
4ed011e01eadb098f74f6237e34aca59
|
|
| BLAKE2b-256 |
d2c564c42cf2f2992aa5ea6e40aecc0d51fec68abbe6c5d2d8ad421e5e4722ce
|
File details
Details for the file project_youler-0.0.1-py3-none-any.whl.
File metadata
- Download URL: project_youler-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d9da5ce0b3ca6ab50ddae2250c402de2bc7ae5c88855af54b555bb642af3175
|
|
| MD5 |
fcac86f43161a3b3d9e3f3acb7b50103
|
|
| BLAKE2b-256 |
2a892c7f7dfa3aba14ab27e86949a634565bf2d832465cbb79bf2e94b074c8e5
|