Skip to main content

Solving a family of puzzles seen on mathoffstickerbook.com

Project description

Sticker book puzzle solver

Aim: automate the process of solving puzzles like this one:

About the family of puzzles

The digits 1 to 9 need to be put in the boxes exactly once so that the six calculations are correct. The calculations are read left to right and top to bottom. Moreover, you should ignore the usual order of operations, so no BODMAS here.

Example

For

4 + 3 x 2,

you should apply the + first, then the x afterwards. So we obtain

(4 + 3) x 2 = 7 x 2 = 14.

Where can I find more puzzles like this one?

Many of them were posted by Matthew Scroggs in the Puzzle Village puzzles from his Big Internet Math-Off Stickerbook webpage, so this family of puzzles will be referred to as stickerbook puzzles. It is now defunct, but the link used to be at http://mathoffstickerbook.com

He still provides these puzzles elsewhere, e.g.:

The package

This package features a class called StickerbookPuzzleSolver; it takes in the puzzle as a string. Currently, the class outputs the answer as a string to print in the terminal.

Package installation

Using pip: pip install stickerbook-puzzle-solver

Using poetry: poetry add stickerbook-puzzle-solver

Note that dashes - must be used in the package name when installing it, while underscores _ are used when importing it in python

Inputting the desired puzzle

Enter the 3 rows and 3 columns in your txt file e.g. "+ + 11" for a row or column saying: ? + ? + ? = 11

So the puzzle in the above image would be saved as follows in a txt file:

+ + 22
+ - 8
/ * 8
+ + 16
+ - 8
/ * 48

Using the class to solve the puzzle

E.g. if the puzzle txt is at ./puzzle/input.txt, the StickerbookPuzzleSolver class can be used as follows:

from stickerbook_puzzle_solver.stickerbook_puzzle import StickerbookPuzzleSolver

puzzle_path = "./puzzle/input.txt"

with open(puzzle_path, 'r') as reader:
    puzzle_string = reader.read()

puzzle = StickerbookPuzzleSolver(puzzle_string)

solved_puzzle = puzzle.solve()

print(solved_puzzle)

Output

The solve method outputs a string; the result from print(solved_puzzle) would look something like:

5 9 8
7 2 1
4 3 6

which tells you how to arrange the digits 1-9 to make all six equations in the puzzle correct. For this example, the digits would be filled in as follows:

Repo demonstration

A demo script called scripts\main.py is included, showing how the class could be used in a simple CLI app.

Setting the demo up

Run the following commands in the terminal:

git clone https://github.com/SmokyFurby/stickerbook.git
cd stickerbook
poetry install
./scripts/main.py --puzzle_path=./puzzle/input.txt

The output should be:

Inputted puzzle:
+ + 22
+ - 8
/ * 8
+ + 16
+ - 8
/ * 48
The solution is:
5 9 8
7 2 1
4 3 6

The Inputted puzzle section repeats the contents of the puzzle txt, while the numbers underneath The solution is shows how to arrange the numbers 1-9 in the puzzle grid to make all six calculations work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stickerbook_puzzle_solver-0.1.6.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

stickerbook_puzzle_solver-0.1.6-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file stickerbook_puzzle_solver-0.1.6.tar.gz.

File metadata

  • Download URL: stickerbook_puzzle_solver-0.1.6.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.11.0 Linux/5.15.0-1021-aws

File hashes

Hashes for stickerbook_puzzle_solver-0.1.6.tar.gz
Algorithm Hash digest
SHA256 b876ad7a1f0de08a58bbae505e338a28b149f62c5e6a6a4de7762c0dce19b7d6
MD5 aaf6727c3a404efa6306a89b6190fd94
BLAKE2b-256 b250510ef2c45fb3726ed6c6ba0f95279078f05b592b319d74065230654b7905

See more details on using hashes here.

File details

Details for the file stickerbook_puzzle_solver-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for stickerbook_puzzle_solver-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e7ae53a92583963c165ee43de28e42a0d878720bc10cbc7921f28338019f00d0
MD5 a64f235b44e7e149a16dcfa5c5044229
BLAKE2b-256 91cbdbec71543ddb151aabe856a78655e1011aa92f6afd7e3dbd6362dfce766f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page