I would like to give some feedback about ...
def countneighbours(grid, row, col):
boxsize = len(grid[0])
if all(boxsize == len(elem) for elem in grid) and 3 <= len(grid) <= 10 and 0 <= row <= boxsize and 0 <= col <= boxsize:
sum = 0
xmin = max(0, col - 1)
xmax = min(boxsize - 1, col + 1)
ymin = max(0, row - 1)
ymax = min(box_size - 1, row + 1)
print (xmin, xmax), (ymin, ymax)
for x in range(xmin, xmax + 1):
for y in range(ymin, ymax + 1):
if x != col or y != row:
print x,y,grid[y][x]
sum += grid[y][x]
return sum
else:
return -1
The minimum box size is 3 and maximum is 10. It must be a box meaning len(row) == len(col). So my solution does not get validated and I have to account for infinately large arrays and rectangles.
From: http://www.checkio.org/mission/count-neighbours/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0
Created at: 2015/03/18 21:49; Updated at: 2015/03/19 05:31