For a while I was getting filtered by part 2, but then I came across a hint that that the number of vertices of a polygon equals the number of sides (for polygons, start with a triangle and then use induction, and here we are just combing squares...) which made this easier to solve. Also helpful was printing out the grid but color-coded (pic 2 shows a test case).