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 YellowTree
def house(plan):
l_plan = plan.split()
hight = []
length = []
for i,j in enumerate(l_plan):
if "#" in j:
hight.append(i)
for k in range(len(l_plan[0])):
for l in range(len(l_plan)):
if "#" in l_plan[l][k]:
length.append(k)
if hight and length:
area = (hight[-1]-hight[0]+1) * (length[-1]-length[0]+1)
else: return 0
return area
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!")
Nov. 22, 2018