Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
20-liner: messed up solution in Creative category for Bacteria Colonies by przemyslaw.daniel
from itertools import product
def healthy_colony(size):
out = [[1]*size for _ in range(size)]
for x, y in product(range(size), range(size)):
a, b, s = 2*(y-x)-1, 2*(x+y)-1, size-1
out[x][y] = 0 if a > s-2 or -a > s or b < s or -b-2 < -3*s else 1
out[x][y] = 2 if a > s-1 or -a-1 > s or b < s-1 or -b-1 < -3*s else out[x][y]
return out
def healthy(grid):
for k, hc in [(k, healthy_colony(k)) for k in range(25, 1, -2)]:
for x, y in product(range(-1, len(grid)-k+2), range(-1, len(grid[0])-k+2)):
if all([hc[i][j] == 2 or hc[i][j] == grid[x+i][y+j]
for i, j in product(range(k), range(k))
if 0 <= x+i < len(grid) and 0 <= y+j < len(grid[0])]):
return x+k//2, y+k//2
return 0, 0
Feb. 18, 2017
Comments: