Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Third solution in Clear category for The Square Chest by ojisan
def find_pset(hz,vt,x,y,m,n,p):
a = hz[y][x+p] * hz[y+n-1][x+p] * vt[y+p][x] * vt[y+p][x+n-1]
return (a)
def multlist(hz,vt,n,m):
t = 0
for y in range(0,m-n+1):
for x in range(0,m-n+1):
r = 1
for p in range(0,n-1):
r = r * find_pset(hz,vt,x,y,m,n,p)
t = t + r
return (t)
def checkio(lines_list):
"""Return the quantity of squares"""
m=4
hz = filter(lambda x:max(x)-min(x)==1,lines_list)
vt = filter(lambda x:max(x)-min(x)==m,lines_list)
hz = [min(x) for x in hz]
vt = [min(x) for x in vt]
hzl = [0 for i in range(m*m)]
vtl = [0 for i in range(m*m)]
for i in hz:hzl[i-1] = 1
for i in vt:vtl[i-1] = 1
hzl=list(zip(*[iter(hzl)]*m))
vtl=list(zip(*[iter(vtl)]*m))
sq = [multlist(hzl,vtl,n,m) for n in range(2,m+1)]
return(sum(sq))
Aug. 7, 2017
Comments: