explaingit

u-pak/constraint-solver

Analysis updated 2026-05-18

0PythonAudience · generalComplexity · 1/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((constraint-solver))
    What it does
      Solves tournament puzzle
      Finds valid match sequences
      Backtracking search
    Tech stack
      Python
    Use cases
      Explore constraint puzzles
      Learn backtracking search
      Simulate tournament outcomes
    Audience
      Students
      Beginners
      Puzzle enthusiasts

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Simulate every possible outcome of the 3-player, 21-match tournament puzzle.

USE CASE 2

Study how backtracking search with pruning solves a constraint satisfaction problem.

USE CASE 3

Use as a teaching example for depth first search in Python.

USE CASE 4

Verify which win-loss sequences reach the exact target match counts for each player.

What is it built with?

Python

How does it compare?

u-pak/constraint-solver0xallam/my-recipe0xhassaan/nn-from-scratch
Stars00
LanguagePythonPythonPython
Last pushed2022-11-22
MaintenanceDormant
Setup difficultyeasymoderatemoderate
Complexity1/52/54/5
Audiencegeneralgeneraldeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

No dependencies beyond Python, the README suggests pasting sc.py into Replit.

In plain English

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.

Copy-paste prompts

Prompt 1
Explain how the backtracking search in this constraint-solver script prunes invalid tournament sequences.
Prompt 2
Help me modify sc.py to solve the same tournament puzzle with different target match counts.
Prompt 3
Walk me through running sc.py in Replit and interpreting its printed solutions.
Prompt 4
Rewrite this constraint solver so it also reports how many valid solutions it found.

Frequently asked questions

What is constraint-solver?

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.

What language is constraint-solver written in?

Mainly Python. The stack also includes Python.

How hard is constraint-solver to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is constraint-solver for?

Mainly general.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Verify against the repo before relying on details.