Imagine a two-dimensional array of boolean values, where the 0s represent squares of grass on a rectangular plot of land and the 1s represent fences.
Write a function that accepts the 2D array as an input and determines whether you can travel from any one area of grass to any other area of grass, using only north/east/west/south movements, without running into a fence.
If any area of grass in the array is fully enclosed by fences (meaning you can't travel N/E/W/S to reach every other area of grass in the array) the function should return false; otherwise, it should return true.
Below are two sample arrays you can use as inputs, although your function should be able to handle not just these but any 2D array of boolean values:
0 0 0 0 0
0 1 0 0 0
0 1 1 1 1
0 0 0 0 0
0 0 0 1 1
(should return true)
0 1 0 1 0
0 1 1 0 0
0 0 0 0 0
0 0 0 1 0
1 1 1 1 0
(should return false, since the middle 0 in the top row is fully enclosed)
Shortest working code wins. I'll pick the winner after either a week has passed or there have been no new submissions within 24 hours.
1 1 1
;1 0 1
;1 1 1
? There is one grass cell in the center. Visually the grass cell in the center is fully enclosed by fences, but by your definition it is not. \$\endgroup\$1
s? What should it return then? \$\endgroup\$