Skip to content

This program can solve matchstick equations, create them, and create images of solutions/ the problems. The version in javascript as a website - https://github.com/KingOfTNT10/KingOfTNT10.github.io

Notifications You must be signed in to change notification settings

K9Developer/Matchstick_Algorithm-Python

Repository files navigation

Contributors Forks Stargazers Issues


Logo

Matchstick Algorithm

This project can solve matchstick puzzels and creates ones
Explore the docs »

View Demo · Report Bug · Request Feature

Website

Table of Contents
  1. About The Project
  2. Usage
  3. Info
  4. Contributing
  5. Contact

About The Project

This project solves any mathematical matchstick puzzels, This algorithm takes a string, for example: 6+4=4, and will look for solutions. For this equation it will find 2:

  1. 0+4=4
  2. 8-4=4

For each one it will explain exactly how to solve. example for the first one: moved the middle of 6 to it's top right to make a 0

example for the second one: added a matchstick to "-" (to make a "+") from the top right of "8" (to make a "6")

(back to top)

Built With

Python

(back to top)

Installation

  1. Clone the repo
    git clone https://github.com/KingOfTNT10/Matchstick_Algorithm-Python.git
  2. Install libraries:
    pip install py_expression
    

(back to top)

Usage

To solve an equation you need to import the algorithm file and call the solve function:

import algorithm

solve_data = algorithm.solve("6+4=4")
print(solve_data)

To create an equation with answers:

import algorithm

# create_equation has one argument called answer, this argument decides what the answer for the random math problem should be
# example: algorithm.create_equation(answer=4)
# It would return for example:
# {'equation': '2+5=4', 'solutions': [{'new_equation': '2+2=4', 'original_equation': '2+5=4', 'explanation': "moved the top left of 5 to it's top right to make a 2"}]}

equation_data = algorithm.create_equation()
print(equation_data)

See the open issues for a full list of proposed features (and known issues).

(back to top)

Info

This program is using a custom format to represent numbers, for example the number 5:\

image

This number is represented like this in the code (other examples can be found in stickData):

[
  [1, 1, 0],
  [0, 1, 1, 1]
]

Because we divide the number into 2 cells/rows:

image

And we number the sticks from left to right (counter-clock wise) (green=1, red=0):

image

So the first cell comes out as:

[1, 1, 0]

And the second:

[0, 1, 1, 1]

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

Your Name - Ilai K - ilai.keinan@gmail.com

Project Link: https://github.com/KingOfTNT10/Matchstick_Algorithm-Python

(back to top)