Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Ground for the House by wo.tomasz
import itertools
def rev(ls):
return [''.join(r) for r in reversed(list(zip(*ls)))]
def nes_no(ls):
hp_b = [ln for ln in itertools.dropwhile(lambda l:len(l.strip("0"))==0, ls)]
hp = [ln for ln in itertools.dropwhile(lambda l:len(l.strip("0"))==0, hp_b[::-1])]
return len(hp)
def house(plan):
ls = plan.strip().split('\n')
y = nes_no(ls)
x = nes_no(rev(ls))
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!")
Dec. 16, 2022
Comments: