Skip to content

Instantly share code, notes, and snippets.

@ap29600
Created December 18, 2025 17:14
Show Gist options
  • Select an option

  • Save ap29600/04449c1ea37e9f9ae000648d811d1067 to your computer and use it in GitHub Desktop.

Select an option

Save ap29600/04449c1ea37e9f9ae000648d811d1067 to your computer and use it in GitHub Desktop.
set of equations for interpreting a puzzle in integer linear programming

assign variables $a_{ij}, b_{ij}, c_{ij}, d_{ij}, e_{ij}, f_{ij}$ for the quadrants, left to right and top to bottom, $i, j \in {1..5}$.

$$ \begin{matrix} \forall i,j: a_{ij} \in {0,1} \ & \forall i,j: b_{ij} \in {0,1} \ & \forall i,j: c_{ij} \in {0,1} \\ \forall i,j: d_{ij} \in {0,1} \ & \forall i,j: e_{ij} \in {0,1} \ & \\ \forall i,j: f_{ij} \in {0,1} \ & & \\ \end{matrix} $$

$$ \begin{matrix} \forall i: \sum_j a_{ij} = 1 \ & \forall i: \sum_j b_{ij} = 1 \ & \forall i: \sum_j c_{ij} = 1 \\ \forall j: \sum_i a_{ij} = 1 \ & \forall j: \sum_i b_{ij} = 1 \ & \forall j: \sum_i c_{ij} = 1 \\ \forall i: \sum_j d_{ij} = 1 \ & \forall i: \sum_j e_{ij} = 1 \ & \\ \forall j: \sum_i d_{ij} = 1 \ & \forall j: \sum_i e_{ij} = 1 \ & \\ \forall i: \sum_j f_{ij} = 1 \ & & \\ \forall j: \sum_i f_{ij} = 1 \ & & \\ \end{matrix} $$

$$ \begin{matrix} & \sum_j j \cdot d_{1j} - \sum_j j \cdot a_{5j} = 2 & \quad \text{stop by Will's two before the sheep dog.} \\ & e_{11} = 1 & \quad \text{Bruce is the sheep dog.} \\ & \sum_j j \cdot d_{2j} - \sum_j j \cdot a_{1j} = 1 & \quad \text{stop by Adam's one before the border collie.} \\ & \sum_j j \cdot f_{5j} - \sum_j j \cdot a_{3j} = 2 & \quad \text{stop by Dora's two before Rocky.} \\ & \sum_j j \cdot a_{5j} - \sum_j j \cdot f_{4j} = 2 & \quad \text{stop by Will's two after Wuff.} \\ & \sum_j j \cdot a_{1j} - \sum_j j \cdot d_{4j} = 1 & \quad \text{stop by Adam's one after the pit bull.} \\ & \sum_j j \cdot a_{2j} - \sum_j j \cdot f_{1j} \ge 0 & \quad \text{stop by Arthur's no later than Bruce.} \\ & \sum_j j \cdot f_{5j} \neq 2 & \quad \text{Roxie is not number 2.}\\ \end{matrix} $$

@ap29600
Copy link
Author

ap29600 commented Dec 18, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment