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 liw_80
def house(plan):
#replace this for solution
if '#' not in plan:
return 0
plan = plan.split('\n')
i = y1 = y2 = x2 = 0
x1 = 10
for p in plan:
i += 1
if "#" in p:
y1 = min(y1, i) if y1 > 0 else i
y2 = max(y2, i)
x1 = min(x1, p.index('#'))
x2 = max(x2, p.rindex('#'))
x = x2 - x1 + 1
y = y2 - y1 + 1
return x * y
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!")
Feb. 3, 2020
Comments: