Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Very naive solution in Clear category for Minesweeper by veky
def checkio(field):
def enumcells():
for i, row in enumerate(field):
for j, cell in enumerate(row): yield i, j, cell
def around(i, j):
from collections import Counter
return Counter(cell for k, l, cell in enumcells()
if abs(k - i) < 2 if abs(l - j) < 2 if (k, l) != (i, j))
def minesrange(i, j):
c = around(i, j)
return range(c[9], c[9] + c[-1] + 1)
def bad():
for i, j, cell in enumcells():
if 0 <= cell < 9 and cell not in minesrange(i, j): return True
critical = [(i, j) for i, j, cell in enumcells() if cell == -1 if set(around(i, j)) != {-1}]
if not critical: return [False, 0, 0]
for i, j in critical:
field[i][j] = -2
if bad(): return [True, i, j]
field[i][j] = 9
if bad(): return [False, i, j]
field[i][j] = -1
March 6, 2014