I have a C# program that creates a series of ever increasing n x n grids.
For each created grid, I create every possible permutation of filled cells in that grid.
For each pattern created by the filled cells, I only want to retain grids where there is a single pattern on the grid - i.e.:
where the number of filled cells = the size of the largest pattern
For the purposes of this program, I only consider shapes to include cells above, below, to the left or to the right of a filled cell - not diagonally
Currently, I'm finding the first cell in the grid (actually modelled in a one-dimensional array) and then calling the following routine recursively:
- Add the passed cell index to a linked list and increment the count
- If there is a filled cell to the left, right, above or below that is not in the list, call the routine with this cell index.
If the final count = the number of filled cells in the grid then retain the pattern, else discard
This doesn't strike me as terribly efficient - is there a better way?