Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Add cells one by one and merge continuous areas solution in Clear category for Radiation Search by Leonix
def checkio(field):
""" Loop over all non-empty cells in a field, maintaining list
of continuous areas processed so far. Merge areas together
when current cell is adjustent to more than one.
"""
areas = []
for y, row in enumerate(field):
for x, cell in enumerate(row):
if cell == 0: continue
neighbours = {(x-1, y, cell), (x, y-1, cell)}
areas, old_areas = [{(x, y, cell)}], areas
for area in old_areas:
if area & neighbours: areas[0] |= area
else: areas.append(area)
return max(([len(area), next(iter(area))[2]] for area in areas), key=lambda a:a[0])
Aug. 17, 2015