Skip to main content

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 check command 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 value all, which means slightly different things to different commands.

You can always pass --help for more detail on a particular command.

  • create <n>: Create problems/pNNNN.py for 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 all covers 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

project_youler-0.1.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

project_youler-0.1.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file project_youler-0.1.0.tar.gz.

File metadata

  • Download URL: project_youler-0.1.0.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

Hashes for project_youler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5af8a96fe1da28318c5e9ea7d4966efbcb68914a9a23a5a494fda0919c2f44af
MD5 b53e51f5da44843ed162f5d00bded80b
BLAKE2b-256 39bb5b46292653bbda062fe486ff7df5503d22aa51f0c2e8a7eabed92385925f

See more details on using hashes here.

File details

Details for the file project_youler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: project_youler-0.1.0-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

Hashes for project_youler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a7c41e92539f50188196202370f76db38be3d20985ece50d30e60e927c66db0
MD5 57d58937705d594cd27d0374f4103deb
BLAKE2b-256 e4bf7b4c8bbcb76133f607f7272ab24f526bacee6c389d8b01ff50797b92ad8b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page