Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
7 lines proc solution in Clear category for Calculate Islands by CDG.Axel
def checkio(land_map, rng=(-1, 0, 1)):
earth, res = {(x, y) for y, row in enumerate(land_map) for x, el in enumerate(row) if el}, []
while earth:
around, res = {earth.pop()}, res + [1]
while around:
around = {(x + dx, y + dy) for x, y in around for dx in rng for dy in rng} & earth
earth, res[-1] = earth - around, res[-1] + len(around)
return sorted(res)
Jan. 29, 2022
Comments: