# Strategy for solving 0hh1 and Unruly?

Q42's game 0hh1 and Simon Tatham's game Unruly are two almost identical logical deduction games. In each one, we're given a square grid which is to be filled by tiles of two colours, and a certain initial setup of given tiles. We need to fill in the rest of the tiles, subject to the following restrictions:

• No three adjacent tiles of the same colour in any row or column.
• Each row and column is equally divided between the two colours.
• (0hh1 only) No two rows and no two columns have identical patterns of colours.

From any initial setup either of the sites can give us, using these criteria will be enough to derive the final solution logically. But what deductions can we make from these criteria, specifically? What are the patterns we should be looking out for in order to fill in new tiles as fast as possible?

## In short, what is the best strategy for solving these games?

• Excellent main-course post to balance our buffet of à la carte puzzles – humn Jan 15 '17 at 23:50

## What to look for

At any stage of play in 0hh1 or Tatham's Unruly, here's what you should be looking for, in order, and what you should do in each case if you find it:

$\def\G #1{\color{green}{\textbf{#1}}}$

1. $\G{Two}$ $\G{adjacent}$ $\G{tiles}$ $\G{of}$ $\G{the}$ $\G{same}$ $\G{colour}$ $\G{in}$ $\G{the}$ $\G{same}$ $\G{row}$ $\G{or}$ $\G{column.}$

If you find this, fill the cells on either side of this pair with the other colour.

1. $\G{An}$ $\G{empty}$ $\G{cell}$ $\G{flanked}$ $\G{by}$ $\G{two}$ $\G{tiles}$ $\G{of}$ $\G{the}$ $\G{same}$ $\G{colour}$ $\G{in}$ $\G{the}$ $\G{same}$ $\G{row}$ $\G{or}$ $\G{column.}$

If you find this, fill this empty cell with the other colour.

1. $\G{A}$ $\G{row}$ $\G{or}$ $\G{column}$ $\G{with}$ $\G{all}$ $\G{of}$ $\G{a}$ $\G{single}$ $\G{colour}$ $\G{already}$ $\G{filled}$ $\G{in.}$

If you find this, fill the rest of that row or column with the other colour.

1. $\G{A}$ $\G{row}$ $\G{or}$ $\G{column}$ $\G{with}$ $\G{all}$ $\G{but}$ $\G{one}$ $\G{of}$ $\G{a}$ $\G{single}$ $\G{colour}$ $\G{already}$ $\G{filled}$ $\G{in,}$ $\G{and}$ $\G{two}$ $\G{empty}$ $\G{cells}$ $\G{adjacent}$ $\G{to}$ $\G{a}$ $\G{tile}$ $\G{of}$ $\G{the}$ $\G{other}$ $\G{colour.}$

If you find this, then one of those two cells must contain the final tile of the first colour in that row/column, so fill all but those two empty cells with the second colour.

The final two configurations to look for are for 0hh1 only, not Tatham's Unruly:

$\def\P #1{\color{purple}{\textbf{#1}}}$

1. $\P{A}$ $\P{row}$ $\P{or}$ $\P{column}$ $\P{with}$ $\P{all}$ $\P{but}$ $\P{two}$ $\P{tiles}$ $\P{filled,}$ $\P{which}$ $\P{is}$ $\P{so}$ $\P{far}$ $\P{identical}$ $\P{to}$ $\P{a}$ $\P{full}$ $\P{one.}$

If you find this, fill the two empty cells in the opposite way from how they are in the corresponding full row/column.

1. $\P{A}$ $\P{row}$ $\P{or}$ $\P{column}$ $\P{with}$ $\P{all}$ $\P{but}$ $\P{one}$ $\P{of}$ $\P{a}$ $\P{single}$ $\P{colour}$ $\P{already}$ $\P{filled}$ $\P{in,}$ $\P{which}$ $\P{is}$ $\P{so}$ $\P{far}$ $\P{identical}$ $\P{to}$ $\P{a}$ $\P{full}$ $\P{one.}$

If you find this, then you know the final tile of that colour must not be in the same position as in the corresponding full row/column, so fill that cell with the other colour.

## Some notes and comparisons

Not all of the above methods, based on possible configurations of tiles to keep an eye out for, are to be applied in the same way.

• 1 and 2 use only the first of the three game restrictions given in the question; 3 uses only the second; 4 uses the first and second together; 5 and 6 use the second and third together.
• 1 and 2 are the easiest configurations to spot. You should always start with these, filling in as many tiles as possible at the beginning until there are no more instances of 1 or 2 on the board. After each application of any of the other techniques, you should then check again to see if that's introduced any more 1 or 2 configurations.
• Many simpler instances of this game can be solved using only 1, 2, and 3, and 5 in the case of 0hh1. 4 and 6 are more advanced techniques, to be used only when nothing else works.

## Demonstrations

First let's see a demonstration of how to spot each of the possible configurations listed above and what to do once you've found one. In each case, I've made at least one gif from each of 0hh1 and Tatham's Unruly, except of course for 5 and 6, which are only valid for 0hh1.

And finally, a couple of example games played out in full. I've deliberately used relatively small boards here, so that the game and its analysis don't go on for too long. Homework for the reader: go and try out the same techniques on larger boards :-)

• A game of 0hh1: solved by a bunch of 1 and 2, 3 in third column, more 1, 3 in second row, another 1, 3 in fourth row, 5 in fifth column w.r.t. second, more 2, 5 in sixth column w.r.t. third, 3 in fifth and sixth rows, 5 in third row w.r.t. second, 3 in first and fourth columns.

• A game of Unruly: solved by a bunch of 1 and 2, 3 in second row, more 1 and 2, 3 in second and seventh columns, more 1 and 2, 3 in third row and sixth column, more 1 and 2, 4 in seventh row, another 1, 3 in sixth row, another 1, 4 in fifth row, 3 in first and third and fourth columns.

• May I propose 4b: if a row or column has all but one of a single color filled in, and there are three consecutive unfilled squares, then fill in all the squares except those three with the other color? This deduction may be used regardless of the presence/position(s) of the other color in that row/column and also in the event the uniqueness constraint does not currently affect the filling of that row or column. (example: B???B??B in an 8x8 instance - neither of the ?s in the right half can be a B) – Will Jan 17 '17 at 9:12
• Good example of needing this: try this one out. – Will Jan 17 '17 at 9:29
• @Will Good one. I'll either reword 4 to incorporate this possibility, or add it as a separate technique. It might take me a while though - ping me again in a week if I haven't done it yet. – Rand al'Thor Jan 17 '17 at 23:50