Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Radiation eater solution in Clear category for Radiation Search by LukeSolo
def checkio(matrix):
height = len(matrix)
width = len(matrix[0])
do_not_hurt = lambda head: 0 <= head[0] < width and 0 <= head[1] < height
def radiation_eater(start_x, start_y):
diet = matrix[start_y][start_x]
heads = {(start_x, start_y)}
eaten = 0
def eat(head_x, head_y):
yummy = matrix[head_y][head_x] == diet
if yummy:
matrix[head_y][head_x] = 0
return yummy
while heads:
x, y = heads.pop()
if eat(x, y):
eaten += 1
heads |= set(filter(do_not_hurt, ((x+1, y), (x, y+1), (x-1, y), (x, y-1))))
return eaten, diet
return max(radiation_eater(x, y) for y in range(height) for x in range(width) if matrix[y][x])
Sept. 30, 2014
Comments: