Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Minesweeper by Juge_Ti
def checkio(mat):
if mat == [[-1]*10]*10:
return [False, 0, 0]
newmat = [x + [10] for x in mat] + [[10]*11]
for i, row in enumerate(mat):
for j, x in enumerate(row):
neighbours = [newmat[i + k//3 - 1][j + k%3 - 1] for k in range(9)]
neighbours[4] = 10
if x == -1 and 0 in neighbours:
return [False, i, j]
if 0 < x < 9 and -1 in neighbours:
k = neighbours.index(-1)
if neighbours.count(9) == x:
return [False, i + k//3 - 1, j + k%3 - 1]
if neighbours.count(9) + neighbours.count(-1) == x:
return [True, i + k//3 - 1, j + k%3 - 1]
if __name__ == '__main__':
#These are just examples
checkio([
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
]) # [False, 0, 0]
checkio([
[0, 2, -1, -1, -1, -1, -1, -1, -1, -1],
[0, 2, -1, -1, -1, -1, -1, -1, -1, -1],
[0, 1, 1, 1, -1, -1, -1, -1, -1, -1],
[0, 0, 0, 1, -1, -1, -1, -1, -1, -1],
[0, 1, 1, 2, -1, -1, -1, -1, -1, -1],
[0, 1, -1, -1, -1, -1, -1, -1, -1, -1],
[0, 1, -1, -1, -1, -1, -1, -1, -1, -1],
[2, 1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1],
]) # [True, 0, 2]
Sept. 13, 2013
Comments: