Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Moore Neighbourhood by TovarischZhukov
def find(data, row, column, i, j):
return data[i][j] and not (row == i and column == j) and \
(max(row - 1, 0) <= i <= min(row + 1, len(data) - 1)) and \
(max(column - 1, 0) <= j <= min(column + 1, len(data[0]) - 1))
def count_neighbours(data, row, column):
return len([val for i, elem in enumerate(data) for j, val in enumerate(elem) if find(data, row, column, i, j)])
Dec. 3, 2015