Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
yield sum(yield) solution in Clear category for The Buttons by flpo
def buttons(ceiling):
ceiling = [[int(x) for x in row] for row in ceiling.split()]
positions = {(i, j) for i, row in enumerate(ceiling) for j, el in enumerate(row) if el}
def close(explore):
while explore:
x, y = explore.pop()
neighbours = {(x + i, y + j) for i, j in ((-1, 0), (0, 1), (1, 0), (0, -1))}
explore.update(neighbours & positions)
positions.difference_update(explore)
yield ceiling[x][y]
def blocks():
while positions: yield sum(close({positions.pop()}))
return sorted(blocks(), reverse=True)
Sept. 29, 2018