
A convolution function is used to identify each of the tile types. A difference function is used to determine the grid shape. The zebra tile is taken as the starting position then some logic is used to step through neighbouring tiles. The code can be found here.