解决摩尔社区的一些问题

时间:2015-07-15 21:53:29

标签: python-2.7

这是我的代码,我不知道如何解决它......

def count_neighbours(grid, row, col):
    neighbor_rule = ((-1, -1), (-1, 0), (-1, 1), (0, -1),
    (0, 1), (1, -1), (1, 0), (1, 1))
    chip = 0
    for each_loc in neighbor_rule:
        n_row = row + each_loc[0]
        n_col = col + each_loc[1]
        if 0 <= n_row < len(gird) and 0 <= n_col < len(gird[0]):
            if gird[n_row][n_col] == 1:
                chip += 1
        else:
            continue
    return chip

0 个答案:

没有答案