Skip to content
This repository has been archived by the owner on May 25, 2024. It is now read-only.

kittyandrew/countdown-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Simple 'Countdown' games solver

Requirements

pyenchant - pip install pyenchant

Numbers countdown game

NumberGame class has two main methods, first get_all() will execute until all possible combinations are checked and return all solutions. get_any() method will return the first found solution, which in some cases decrease runtime to less than one second.

>>>from countdown_solvers import NumberGame
>>>game = NumberGame([100, 25, 3, 1, 5, 8], 666)
>>>solution = game.get_any()
>>>print(solution)
 ... ('(100+25+8)*5+1', 666)
Async class

**You should not use this class unless you know what you are doing.** Package also have async adaptation of NumberGame class. I added this implementation to use as a module to telegram userbot, because it will allow my bot to keep control and react to commands while executing this cpu heavy task.

>>>from countdown_solvers import AsyncNumberGame
>>>game = AsyncNumberGame([75, 50, 9, 1, 4, 2], 777)
>>># Assuming async context
>>>solutions = await game.get_all()
>>>print(*solutions, sep="\n")
 ... ('75*9+2*(50+1)', 777)
 ... ('75*9+2*(1+50)', 777)
 ... ('(50+1)*2+75*9', 777)
 ... ('(50+1)*2+9*75', 777)
 ...  ... 
 ... ('(2+50+1)*9+75*4', 777)
 ... ('(2+50+1)*9+4*75', 777)
 ... ('(2+1+50)*9+75*4', 777)
 ... ('(2+1+50)*9+4*75', 777)

Words countdown game

TextGame class finds all possible combinations of symbols that are legit words. Although, it just ignores combinations that are less then 4 symbols, because enchant lib that is used for checking doesn't work properly in such case. ¯\_(ツ)_/¯
You can still use bad_search to find all words, also you can reverse search with from_smaller=True.

>>>from countdown_solvers import TextGame
>>>game = TextGame(["a", "b", "c", "d", "e", "f", "g", "h"])
>>>solutions = game.get_all(from_smaller=True, bad_search=True)
>>>print(*solutions, sep="\n")
 ... chafed
 ... beach
 ... badge
 ... decaf
 ... faced
 ... cadge
 ... caged
 ...  ... 
 ... deaf
 ... fade
 ... aged
 ... egad
 ... head
 ... chef
>>>best_solution = game.get_best()
>>>print(best_solution)
 ... chafed

Mentions

Thanks to @painor (Github:painor) and another guy from telethonofftopic telegram chat for writing code for me and fixing mine helping much to implement this module!

About

Countdown games solver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages