Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ground for the House by Dr__ON
def house(plan):
rows = []
plan = plan.split()
for elem in plan:
if '#' in elem:
if elem.count('#') > 1:
rows.append(elem.rindex('#') - elem.index('#') + 1)
else:
rows.append(elem.index('#') + 1)
cols = [i for i,e in enumerate(plan) if '#' in e]
return max(rows) * (max(cols) - min(cols) + 1) if rows else 0
if __name__ == '__main__':
print("Example:")
print(house('''
0000000
##00##0
######0
##00##0
#0000#0
'''))
#These "asserts" using only for self-checking and not necessary for auto-testing
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
''') == 0
assert house('''
0##0
0000
#00#
''') == 12
print("Coding complete? Click 'Check' to earn cool rewards!")
April 2, 2019