Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Corrected solution in Uncategorized category for Minesweeper by altarfinch
ADJ = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
COVERED, EMPTY, MARKED = -1, 0, 9
def getNeighboors(i,j,field):
covered, marked = [], []
for iA, jA in ADJ:
iN, jN = i + iA, j + jA
if 0 <= iN < 10 and 0 <= jN < 10:
if field[iN][jN] == COVERED:
covered += [(iN,jN)]
elif field[iN][jN] == MARKED:
marked += [(iN,jN)]
return covered, marked
def checkio(field):
for i, row in enumerate(field):
for j, cell in enumerate(row):
if field[i][j] not in [COVERED, EMPTY, MARKED]:
covered, marked = getNeighboors(i,j,field)
if field[i][j] == len(covered) + len(marked) and len(covered):
return [True, covered[0][0], covered[0][1]]
elif field[i][j] == len(marked) and len(covered):
return [False, covered[0][0], covered[0][1]]
return [False, 0, 0]
Sept. 18, 2013
Comments: