Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: recursive solution in Clear category for The Buttons by przemyslaw.daniel
def buttons(ceiling):
ceiling, visited = ceiling.split(), set()
height, width = range(len(ceiling)), range(len(ceiling[0]))
valid = {(x, y) for x in height for y in width}
def serach(x, y):
if (x, y) not in (valid-visited) or ceiling[x][y] == '0':
return 0
visited.add((x,y))
points = [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]
return int(ceiling[x][y])+sum(serach(i, j) for i, j in points)
result = [serach(x, y) for x in height for y in width]
return sorted([x for x in result if x], reverse=True)
Sept. 24, 2018
Comments: