I would like to give some feedback about ground for the house task. When I checked the solution, I received an error saying that the correct answer for the extra test 2 should be 50 and my solution gives 40.
The area of the house testing is as follows: Fail:house("0000##0000\n#000##000#\n##########\n##000000##\n0########0\n") But when I copied "test house" into my idle, it returned 50 as it supposed to. So I would like to know where have I mistaken. Thank you for your help!
From: https://py.checkio.org/mission/ground-for-the-house/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
def house(plan):
import re
k=1
x=re.split(r"\n",plan)
g=[]
b=[]
minm=(len((x[k])))
maxm=0
while k<(len(x)-1):
for i in range (0,(len(x[k]))):
if x[k][i]=="#" and i<minm:
minm=i
if x[k][i]=="#" and i>maxm:
maxm=i
if minm!=(len((x[k]))) or maxm!=0:
if minm==maxm:
g.append(1)
elif minm!=maxm:
f=((maxm-minm)+1)
g.append(f)
else:
g.append(0)
k+=1
minm=(len((x[k])))
maxm=0
for i in range((len(g))):
if g[i]!=0:
b.append(i)
if b!=[]:
length=((max(b)-min(b))+1)
width=max(g)
area=length*width
return area
else:
return 0
Created at: 2019/11/30 16:03; Updated at: 2019/12/01 06:29