Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Speedy category for Ground for the House by Merzix
def house(plan):
plan = plan.split()
plan_width = len(plan[0])
height = 0
max_width_index = 0
min_width_index = plan_width
height_adder = 0
for row in plan:
if '#' in row:
min_width_index = min(min_width_index, row.index('#'))
max_width_index = max(max_width_index, plan_width - row[::-1].index('#'))
height += 1 + height_adder
height_adder = 0
else:
height_adder += 1 if height else 0
return height * (max_width_index - min_width_index)
if __name__ == '__main__':
assert house('''
0000000
##00##0
######0
##00##0
#0000#0
''') == 24
assert house('''0000000000
#000##000#
##########
##000000##
0000000000
''') == 30
assert house('''0000
0000
#000
''') == 1
assert house('''0000##0000
#000##000#
##########
##000000##
0########0
''') == 50
assert house('''0000
0000
0000
''') == 0
assert house('''0000000000
000###0000
000#######
000###0000
''') == 21
assert house('''0000
#000
0#00
00#0
''') == 9
assert house('''0##0
0000
#00#
''') == 12
Sept. 4, 2018