Series: Modeling logic puzzles
Phần: 7 / 91. Introduction
A puzzle a day is a packing puzzle described as follows: given a calendar-shaped board of size cells, where the 43 valid cells are split into 12 cells holding month abbreviations (the top 2 rows), 31 cells holding the day numbers (the remaining 5 rows), and 6 remaining cells in the top-right and bottom-right corners that don't belong to the board. The player has 8 polyomino pieces (each made of 5 or 6 unit squares) and must place all of them on the board, rotating and flipping each piece as needed, satisfying:
- Each piece is used exactly once
- No two pieces overlap
- Every valid cell on the board is covered, except exactly 2 cells - the cell for the month and the cell for the day to be displayed
The two cells left uncovered are exactly "today's date" that the puzzle displays - which is also why this puzzle is called A puzzle a day, since almost every day of the year has a (or several) different arrangement to discover.
Below is an example solution for July 23rd
2. Modeling puzzle
- is the set of coordinates of the valid cells on the board (43 cells, after removing the 6 cells that don't belong to the calendar)
- is the cell corresponding to the month to display
- is the cell corresponding to the day to display
- is the set of names of the 8 pieces used to cover the board, each piece having a fixed shape made of 5 or 6 adjacent unit squares
- For each piece , generate every rotated () and mirrored variant of the piece, then for each variant, scan every translated position on the board and keep only the positions where the whole piece fits inside . Let be the set of all valid configurations (placements) obtained for piece , where each configuration corresponds to a set of cells occupied by piece when placed according to that configuration
2.1. Decision variables
For each piece and each configuration , define variable such that
2.2. Constraints
- Each piece is placed according to exactly one configuration
- Each valid cell is covered the required number of times: ordinary cells must be covered by exactly one piece, while the month cell and the day cell must not be covered by any piece
2.3. Objective function
Just like Troix, this is a feasibility problem: we only need to find one way to place the 8 pieces that satisfies all the constraints, without minimizing or maximizing anything. So the objective function is simply set to a constant (I chose 0).
3. Conclusion
This is a model of the well-known calendar packing puzzle called A puzzle a day. With this model, you can plug in any date and immediately get a valid arrangement of the 8 pieces for that day, instead of having to figure it out by hand.
The Python code for A puzzle a day modeling is available at Tung-hehe
Happy modeling!

