nyt-digits-solver
Puzzle solver for the NYT Digits game (no longer active).
Given a set of numbers and a target, finds the sequence of arithmetic operations (+, -, *, /) that produces the target. Also lets you explore all values reachable from a given input, with the steps to get there.
Installation
pip install nyt-digits-solver
Usage
solve
Returns a list of solutions. Each solution is a list of Step(numbers, operation) where operation is the step that produced that state (None for the initial state).
import nyt_digits_solver as ds
solutions = ds.solve([1, 2, 3], target=6)
# [
# [
# Step(numbers=[1, 2, 3], operation=None),
# Step(numbers=[3, 3], operation='2+1'),
# Step(numbers=[6], operation='3+3'),
# ]
# ]
for step in solutions[0]:
if step.operation:
print(f"{step.operation} → {step.numbers}")
# 2+1 → [3, 3]
# 3+3 → [6]
Find all solutions instead of just the first:
all_solutions = ds.solve([1, 2, 3, 4, 5, 25], target=452, how_many_sols=None)
explore
Returns a dict mapping every reachable value to the shortest list of Steps that produces it.
result = ds.explore([2, 3])
# {
# 5: [Step(numbers=[2, 3], operation=None), Step(numbers=[5], operation='3+2')],
# 1: [Step(numbers=[2, 3], operation=None), Step(numbers=[1], operation='3-2')],
# 6: [Step(numbers=[2, 3], operation=None), Step(numbers=[6], operation='3*2')],
# }
# Check if a target is reachable
if 452 in ds.explore([1, 2, 3, 4, 5, 25]):
print("reachable!")
# Get the steps to a specific value
steps = ds.explore([1, 2, 3, 4, 5, 25])[452]
for step in steps:
if step.operation:
print(f"{step.operation} → {step.numbers}")
CLI
nyt-digits-solver -n 1,2,3 -t 6
# Found 1 solution. Took 0.0 seconds.
# Start: [1, 2, 3]
# 2+1 → [3, 3]
# 3+3 → [6]
# Find all solutions
nyt-digits-solver -n 1,2,3,4,5,25 -t 452 -c 0
Metadata
Release files for nyt-digits-solver 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nyt_digits_solver-0.2.1.tar.gz | 3.9 kB | Without provenance | Details for nyt_digits_solver-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nyt_digits_solver-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for nyt_digits_solver-0.2.1-py3-none-any.whl |
Total release size: 8.2 kB
Release files / nyt_digits_solver-0.2.1.tar.gz
| Download URL | nyt_digits_solver-0.2.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d9d5fb05d00ab31709fe81bfdc640c1fc0a54d730ea169613d12472d38c73be8
|
|
BLAKE2b-256 checksum How to use checksums |
b25935a1592d9f5c96ca754ba98004a9303ac0458ee29f29dc75d3938afa8897
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / nyt_digits_solver-0.2.1-py3-none-any.whl
| Download URL | nyt_digits_solver-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a09847a6bf146d2233ca25bb78f563740399eccdc560ce7c2037c0d75cd64fa
|
|
BLAKE2b-256 checksum How to use checksums |
0cadf8ef06264b5f6cd1d9c0ada4e9f3025bb4661ce8389c5b84078fa643207b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for nyt-digits-solver 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.