1 . . . 1
. . . 1 .
2 4 . . .
1 . 2 1 .
3 . 1 . 2
The goal is to complete the grid by dividing it into "regions" (where a region is a maximally contiguous set of cells connected by their edges) where each cell in a region is labelled with the size of the region. Thus, a 1-region will contain a single 1 and have no bordering 1-regions; a 2-region will consist of two neighbouring cells containing 2s and have no bordering 2-regions; and so forth. Some regions may start with more than one cell filled in; some may have no clues filled in at the start. The solution to the problem above is
1 4 2 2 1
2 4 4 1 4
2 4 2 4 4
1 3 2 1 4
3 3 1 2 2
This is a surprisingly difficult puzzle to model due to the region contiguity constraints. My solution works as follows:
- each cell is a potential "root" of a region (and each region has a single root);
- neighbouring cells are either in the same region (and hence have the same number) or are in different regions (which must have different numbers);
- each cell has a time step at which we label it (region roots are labelled at step 1, all other cells are labelled later);
- any cell labelled at step t > 1 must be part of the region of a neighbouring cell labelled at step t;
- each region must be labelled with the size of the region.
No comments:
Post a Comment