Suppose you get the following array:
foo = [ [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,1,1,1,1,1,0,0], [0,0,0,1,0,0,0,1,0,0], [0,0,0,1,0,0,0,1,0,0], [0,0,0,1,1,1,0,1,0,0], [0,0,0,0,0,1,0,1,0,0], [0,0,0,0,0,1,1,1,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], ]
How to determine if pattern 1s is a closed loop? I struggled with this for several days. I tried a recursive loop to search for neighbors and words, but when you have a more complex template, it will not work, for example:
foo = [ [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,1,1,1,0,0,0,0], [0,0,0,1,0,1,0,0,0,0], [0,0,0,1,0,1,0,0,0,0], [0,0,0,1,1,1,1,1,0,0], [0,0,0,0,0,1,0,0,0,0], [0,0,0,0,0,1,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0], ]
Does anyone have a magic algorithm to solve this ?: (