Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for The Square Chest by TovarischZhukov
# migrated from python 2.7
def check(data):
k=len(data)/4; m=min(data)
return set(list(range(m,m+k+1))+list(range(m,4*k+m+1,4))+list(range(4*k+m+1,5*k+m+1))+list(range(m+k,5*k+m+1,4)))==set(data)
def find(retval,dct_data,points,current,path):
if current in points: points.remove(current)
path.append(current)
for val in dct_data[current]:
if val!=current:
if val not in path: find(retval,dct_data,points,val,path[:])
else:
ch=path[path.index(val):]
if sorted(ch) not in retval and check(ch):
retval.append(sorted(ch))
def checkio(lines):
dct_data={}; retval=[]
for val in lines:
if val[0] not in dct_data: dct_data[val[0]]=[]
dct_data[val[0]]+=[val[1]]
if val[1] not in dct_data: dct_data[val[1]]=[]
dct_data[val[1]]+=[val[0]]
points=list(dct_data.keys())
while points: find(retval,dct_data,points,points[0],[])
return len(retval)
Jan. 29, 2016