We have a system which contains a rectangular array of components. Some of these components may have already failed but the system is highly redundant. The system will be able to work as long as there is at least one collection of n or more working components that are connected. A pair of components are connected if there is a path of adjacent components (horizontally, vertically, or diagonally) within the collection that goes from one component to the other component. A collection of components is connected if all pairs of components within the collection are connected.
We want to be able to estimate the chances of system failure. We call a component
"critical" if its failure would bring down the system.
Create a class SysFailure that contains a method critical that
is given n and the current state of the rectangular array and that returns the number
of critical components. If the system has already failed, return -1.
state will be given by a String of '0's and '1's
where a '1' indicates a working component and a '0' represents a
failed component. Each element of state represents a row of components, in order
from top row to bottom row.