For fans of all other kinds of logic puzzles

Following the publication of my book, "Pattern-Based Constraint Satisfaction and Logic Puzzles (Second Edition)" (PBCS2), in which there is a full chapter dedicated to Slitherlink, I'll give here the detailed solution of a few Slitherlink puzzles according to the resolution model developed in the book - if anyone is still interested in Slitherlink (the topic hasn't been active for a long time).

I'll take the examples discussed in the old thread: http://forum.enjoysudoku.com/solving-slitherlink-puzzles-t31264.html, which I opened little after I discovered Slitherlink on some website. What I wrote there is now largely superseded by what's in the book.
And, as my resolution model is now complete, I preferred to open a new thread.

First, a few definitions and notations (details can be found in the book):

Given a mxn grid (m rows and n columns of cells), there are:
- m+1 rows and n columns of possible horizontal lines
- m rows and n+1 columns of possible vertical lines
the horizontal line at the top of cell r3c7 is named Hr3c7
the vertical line at the left of cell r3c7 is named Vr3c7

There are 3 types of "natural" CSP-Variables (associated with straightforward representations of the givens and solution):
- Nrc represents the number of borders of cell (r, c) touching the solution loop
- Hrc represents the upper border of cell (r, c), Hrc = 1 if it touches the solution loop, 0 otherwise
- Vrc represents the left border of cell (r, c), Vrc = 1 if it touches the solution loop, 0 otherwise
Notice that all the resolution rules presented in the literature use only these CSP-Variables (in their own, usually informal, ways).

As always in my approach, there are additional CSP-Variables, with symbols n, e, s, w representing the cardinal directions:
- Prc represents the point at the upper left corner of cell (r, c). Its values can only be o, nw, ne, sw, se, ns, ew (representing which lines going through it do belong to the solution loop, with obvious restrictions for cells at the edges and corners.
- Brc represents the border of cell (r, c). Its values can only be o, n, s, w, e, nw, ne, sw, se, ns, ew, wne, nes, esw, swn (representing which lines of the border do belong to the solution loop), with obvious restrictions for cells at the edges and corners.
Optionally, there is one more type of CSP-Variables:
- Irc represents whether cell (r, c) is inside (Irc = 1) or outside (Irc = 0) the solution loop.

Notice that, with the values allowed for Prc CSP-Variables, the basic fact that a point can only have 0 or 2 lines touching it is automatically taken into account.
Last edited by denis_berthier on Sat Aug 08, 2015 8:49 am, edited 1 time in total.
denis_berthier
2010 Supporter

Posts: 1321
Joined: 19 June 2007
Location: Paris

### Easy example

The first example in the old thread was the following easy 7x7 puzzle:

Code: Select all
`. 0 2 3 3 3 2 0 . . . . . 3 2 . 2 . . . 1 . . . . . . 2 . . . . . . 3 3 1 3 1 1 2 3 . . . . 2 . . `

Here is the full resolution path.
Notice that, as always with such kinds of puzzles involving large numbers of candidates, most steps (singles) are trivial and would be applied by a human player without even thinking about it. They make the resolution path look very long, but I preferred to keep them, at least for a first example.
All the (classical) non-single rules that appear in the path are "macro-rules", i.e. they can be replaced by sequences of singles and whips[1], as proven in PBCS2.
The LOOP[k] are what allows to take into account the only-one-loop global constraint. They are not really necessary here. They could be replaced by rules for innies and outies (using the Irc CSP-variables).

Hidden Text: Show
Code: Select all
`0-in-r1c2 ==> Hr2c2 = 0, Hr1c2 = 0, Vr1c3 = 0, Vr1c2 = 00-in-r2c1 ==> Hr3c1 = 0, Hr2c1 = 0, Vr2c2 = 0, Vr2c1 = 02-in-ne-corner ==> Vr2c8 = 1, Hr1c6 = 1diagonal-3s-in-{r1c6...r2c7} ==> Vr1c6 = 1, Hr3c7 = 1, Vr3c8 = 0, Hr1c5 = 03+diagonal-2-symmetric-corner-in-{r5c7+r4c7...ne} ==> Vr5c8 = 1, Hr6c7 = 1, Vr6c8 = 03+diagonal-2-symmetric-corner-in-{r1c4+r1c3...nw} ==> Vr1c5 = 1, Hr1c4 = 13-in-r6c7-hit-by-verti-line-at-ne ==> Vr6c7 = 1, Hr7c7 = 1diagonal-3-2-in-{r5c7...r6c6}-non-closed-sw-corner ==> Vr6c6 = 1, Hr5c7 = 1, Vr4c8 = 03-in-r1c5-hit-by-horiz-line-at-ne ==> Hr2c5 = 13-in-r1c4-hit-by-horiz-line-at-se ==> Vr1c4 = 12-in-r1c3-open-nw-corner ==> Hr2c3 = 1, Vr2c4 = 0, Pr2c4 = nw3-in-r1c6-hit-by-horiz-line-at-sw ==> Vr1c7 = 1adjacent-1-3-on-edge-in-{r3 r2}c7 ==> Vr3c7 = 0, Hr4c7 = 02-in-r4c7-open-ne-corner ==> Vr4c7 = 1, Hr5c6 = 0, Pr5c7 = nespecial-1-single-e-in-r6c5 ==> Vr6c5 = 0, Hr7c5 = 0, Hr6c5 = 0singles: Pr7c6 = ns, Vr7c6 = 1, Pr6c6 = ns, Vr5c6 = 1special-N-single: Nr5c6 = 1singles: Pr4c7 = sw, Hr4c6 = 1, Pr4c2 = nw, Hr4c1 = 1, Hr4c2 = 0, Vr3c2 = 1, Vr4c2 = 0special-2-single-se-in-r3c1 ==> Vr3c1 = 0singles: Pr4c1 = se, Vr4c1 = 1, Pr3c2 = se, Hr3c2 = 1, Pr2c7 = ne, Hr2c7 = 1, Vr2c7 = 0, Pr3c7 = ew, Hr3c6 = 1special-N-single: Nr2c6 = 1singles: Pr2c3 = se, Vr2c3 = 1special-N-singles: Nr2c2 = 2, Nr3c2 = 2, Nr2c3 = 22-in-r3c3-open-nw-corner ==> Hr4c3 = 1, Vr3c4 = 1, Hr4c4 = 0, Vr4c4 = 0, Pr4c4 = nwsingles: Pr4c3 = se, Vr4c3 = 1, Pr3c4 = se, Hr3c4 = 1special-N-single: Nr2c4 = 1singles: Pr2c2 = o, Pr7c8 = sw, Vr7c8 = 1, Nr7c7 = 33-in-se-corner ==> Hr8c7 = 1singles: Pr8c7 = ew, Hr8c6 = 1special-N-single: Nr7c6 = 2diagonal-3-2s-in-{r5c7...r7c5}-non-closed-sw-end ==> Vr7c5 = 1singles: Pr7c5 = sw, Hr7c4 = 13-in-r6c3-hit-by-horiz-line-at-se ==> Vr6c3 = 1, Hr6c3 = 1, Vr7c4 = 0adjacent-1-3-on-pseudo-edge-in-r6{c2 c3} ==> Vr6c2 = 0, Hr7c2 = 0adjacent-1-3-on-pseudo-edge-in-r6{c4 c3} ==> Hr7c3 = 1, Hr6c4 = 0special-3-single-swn-in-r6c3: Vr6c4 = 0special-3-single-e-in-r6c1 ==> Vr6c1 = 1, Hr7c1 = 1, Hr6c1 = 1singles: Pr8c1 = o, Hr8c1 = 0, Pr5c1 = ne, Hr5c1 = 1special-N-single: Nr4c1 = 3singles: Pr7c2 = sw, Vr7c2 = 1special-N-single: Nr7c1 = 22-in-sw-corner ==> Hr8c2 = 1special-N-single: Nr7c2 = 2singles: Pr8c3 = ew, Hr8c3 = 1special-N-single: Nr7c3 = 2singles: Pr8c4 = ew, Hr8c4 = 1special-N-single: Nr7c4 = 3singles: Pr6c2 = nw, Vr5c2 = 1special-N-singles: Nr5c1 = 3, Nr5c2 = 1, Nr4c2 = 1singles: Pr5c3 = ne, Hr5c3 = 1special-N-single: Nr4c3 = 3singles: Pr6c4 = nw, Vr5c4 = 1special-N-single: Nr5c3 = 3singles: Pr7c4 = ew, Pr6c5 = o, Vr5c5 = 0special-N-single: Nr5c4 = 1singles: Pr4c8 = o, Pr3c1 = o, Pr2c1 = o, Vr1c1 = 0, Nr1c1 = 00-in-r1c1 ==> Hr1c1 = 0singles: Pr1c1 = o, Pr1c3 = o, Pr1c2 = o, Pr1c8 = o349 candidates, 333 csp-links and 903 links. Density = 1.49%LOOP[14]: Hr4c6-Vr4c7-Hr5c7-Vr5c8-Hr6c7-Vr6c7-Hr7c7-Vr7c8-Hr8c7-Hr8c6-Vr7c6-Vr6c6-Vr5c6- ==> Vr4c6 = 0special-N-single: Nr4c6 = 2singles: Pr5c6 = sw, Hr5c5 = 1special-N-single: Nr5c5 = 2singles: Pr5c5 = ne, Vr4c5 = 1special-N-single: Nr4c4 = 1LOOP[16]: Hr4c6-Vr4c7-Hr5c7-Vr5c8-Hr6c7-Vr6c7-Hr7c7-Vr7c8-Hr8c7-Hr8c6-Vr7c6-Vr6c6-Vr5c6-Hr5c5-Vr4c5- ==> Hr4c5 = 0special-N-single: Nr4c5 = 2singles: Pr4c5 = ns, Vr3c5 = 1special-N-singles: Nr3c4 = 3, Nr2c5 = 1singles: Pr3c6 = se, Vr3c6 = 1special-N-singles: Nr3c6 = 3, Nr3c5 = 2`

and the solution

Code: Select all
`.   .   .   .———.   .———.   .      0   2 | 3 | 3 | 3 | 2  .   .   .———.   .———.   .———.  0     |                 3 |.   .———.   .———.   .———.———.  2 |     2 |   |   |     1  .———.   .———.   .   .———.   .|       |       |       | 2  .———.   .———.   .———.   .———.    |       |       |     3 |.———.   .———.   .   .   .———.| 3   1 | 3   1   1 | 2 | 3  .———.   .———.———.   .   .———.    |           | 2 |       |.   .———.———.———.   .———.———.`
denis_berthier
2010 Supporter

Posts: 1321
Joined: 19 June 2007
Location: Paris