u-pak/constraint-solver — explained in plain English
Analysis updated 2026-05-18
Simulate every possible outcome of the 3-player, 21-match tournament puzzle.
Study how backtracking search with pruning solves a constraint satisfaction problem.
Use as a teaching example for depth first search in Python.
Verify which win-loss sequences reach the exact target match counts for each player.
| u-pak/constraint-solver | 0xallam/my-recipe | 0xhassaan/nn-from-scratch | |
|---|---|---|---|
| Stars | 0 | — | 0 |
| Language | Python | Python | Python |
| Last pushed | — | 2022-11-22 | — |
| Maintenance | — | Dormant | — |
| Setup difficulty | easy | moderate | moderate |
| Complexity | 1/5 | 2/5 | 4/5 |
| Audience | general | general | developer |
Figures from each repo's GitHub metadata at analysis time.
No dependencies beyond Python, the README suggests pasting sc.py into Replit.
This project is a constraint solver written in Python that works through a math puzzle about a small tournament. The puzzle involves three players, named A, B, and C, who play a total of 21 matches. Each player has a target number of matches they must end up having played: A needs to reach 17, B needs 15, and C needs 10. The rules of the tournament are simple. Only two players play in any given match while the third player rests. Whoever wins a match stays at the table for the next one, and whoever loses is swapped out for the player who was resting. The program's job is to work out which sequences of wins and losses, starting from an opening match between A and B while C rests, could produce a tournament where the final participation counts match the targets exactly. To solve this, the code uses a backtracking search, sometimes called depth first search with pruning. It tries out possible outcomes step by step, and whenever a player's match count goes over their target, it abandons that branch early instead of continuing to explore it. This keeps the search efficient even though the total number of possible match sequences could otherwise be large. The program is capped so it never tries to simulate more than 21 total matches, since that is the fixed total from the puzzle. When it finds a valid tournament history that matches all three targets, it prints out the early matches of that solution. The README notes it can also surface every kind of outcome, both valid and invalid combinations, as part of exploring the full search space. To try it, you can paste the file sc.py into an online environment like Replit and run it directly. The puzzle itself was created by Adrian Paenza, and the README links to a Wikipedia page about him for background.
A Python backtracking solver that figures out which win-loss sequences in a 3-player, 21-match tournament match a fixed target for how many games each player plays.
Mainly Python. The stack also includes Python.
Setup difficulty is rated easy, with roughly 5min to a first successful run.
Mainly general.
This repo across BitVibe Labs
Don't trust strangers blindly. Verify against the repo.