ILP Part 89 — Poles

This is the eightieth ninth part of the ILP series. For your convenience you can find other parts in the table of contents in Part 1 – Boolean algebra

Today we are going to solve Słupki rosną riddle. We have a board chipped into multiple parts. We need to build poles of different heights so that each chipped part has at most four fields selected.

Code:

First, we define a board. Next, we make sure that each part has exactly four fields selected (line 27).
Next, we make sure that poles are continuous and going up (lin 32). If the field below wasn’t selected then field above cannot be selected either which we represent with less or equal constraint.
Finally, we make sure that all poles are of a different height (lines 36-38).

Output: