Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Spaceship Landing Strip by flpo
from itertools import takewhile, chain
def histograms_area(row):
for i, cell in enumerate(row):
if not cell: continue
next_lt = lambda sub: len(list(takewhile(lambda x: x >= cell, sub)))
yield cell * (1 + next_lt(row[:i][::-1]) + next_lt(row[i+1:]))
def histograms(grid):
histogram = [0] * len(grid[0])
for i, row in enumerate(grid):
for j, cell in enumerate(row):
histogram[j] = histogram[j] + 1 if cell in 'GS' else 0
yield histogram
def checkio(grid):
return max(chain.from_iterable(map(histograms_area, histograms(grid))))
Sept. 8, 2017