Your input is an array of integers in the range [-1,4]
. An array element of -1
means that there might be a bomb in that position. A non-negative element means that there is not a bomb in that position and also the numeric value tells how many bombs there are within distance 2.
For example, if we have the following array:
[1,2,-1,-1,4,-1,-1,-1,1]
it's possible to infer that every -1
except the last one contains a bomb.
Your task is to take indicate which -1
for sure doesn't contain a bomb by outputting it's index (0 or 1 based). There is always at least one guranteed bombfree square (and thus the input length is at least two). You can use another number instead of -1
to represent an unknown square. If there are multiple possibilities output at least one of them. Shortest code wins.
To reiterate, you have to be certain that the index you output cannot contain a mine. If you were clearing mines IRL, you probably would also like to know that you won't accidentally step on one.
Test cases
[-1,0] -> 0
[0,1,-1,-1] -> 2
[-1,-1,-1,0] -> 1 or 2
[1,-1,-1,-1,2] -> 1
[-1,2,-1,-1,4,-1,-1] -> 0
[-1,-1,3,-1,-1,2,2,-1] -> 3
[2,-1,-1,-1,2,-1,-1,-1,2] -> 3 or 5
[-1,-1,1,-1,-1,-1,-1,1,0] -> 6
[-1,-1,1,-1,-1,2,-1,-1,2,-1,-1,2,-1,1] -> 0 or 1
2
would be a valid output, right? If there were to be no bomb in index2
, then there would be no bomb within two spaces from the first element, and one bomb (the last one) in the vicinity of the second element. \$\endgroup\$-1
indicator? \$\endgroup\$