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 SnakeInTheLake
def house(plan):
if '#' not in plan:
return 0
lines = plan.strip().split()
chars = ''.join(lines)
width = (chars.rfind('#') // len(lines[0]) - chars.find('#') // len(lines[0])) + 1
length = 0
for line in lines:
if '#' in line:
left = line.find('#')
right = line.rfind('#')
if left == right:
length = max(length, right + 1)
else:
length = max(length, right - left + 1)
return width * length
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!")
June 3, 2019