Vin Diagrams
Jump to navigation
Jump to search
This problem effectively asks us the number of dots inside two loops on an ascii grid. Algorithmicaly, this isn't super challenging, it's just we have to code it up right.
One easy way to do it is to:
- identify the A and then flood-fill the A ring with all A's (except for intersections...they can stay X
- repeat with B
- these two steps just allow us to more easily identify loops moving on forward
- walk around the edge of the input grid and flood fill any '.' to something else to easily determine what is and is not inside a loop.
- find some '.' which is still left. Flood fill to the edge. We can determine whether it's A, B, or both depending on the boundaries we hit while flood filling
- repeat for any remaining dots