I would like to give some feedback about ...
From: http://www.checkio.org/mission/one-line-drawing/solve/
HTTP_USER_AGENT:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
mydict={}
mypoints=[]
mylevel = 0
def inPaths( p1, p2, data):
for item in data:
if p1[0] == item[0] and p1[1] == item[1] and p2[0] == item[2] and p2[1] == item[3]:
return True
if p1[0] == item[2] and p1[1] == item[3] and p2[0] == item[0] and p2[1] == item[1]:
return True
return False
def inCurPath( p1, p2, curpath):
for i in range(0, len(curpath)-1):
if p1[0] == curpath[i][0] and p1[1] == curpath[i][1] and p2[0] == curpath[i+1][0] and p2[1] == curpath[i+1][1]:
return True
if p2[0] == curpath[i][0] and p2[1] == curpath[i][1] and p1[0] == curpath[i+1][0] and p1[1] == curpath[i+1][1]:
return True
return False
def findNextPoint( curpath ,data):
global mydict
if curpath[0] not in mydict:
mydict[ curpath[0] ] = curpath
path = mydict[ curpath[0] ]
#save longer path
if len(path) < len(curpath):
mydict[ curpath[0] ] = curpath
for item in mypoints:
if inPaths( curpath[-1], item,data)== True and inCurPath( curpath[-1],item, curpath) == False:
#print( "new item:", item, "curpath=",curpath)
curpath.append( item )
findNextPoint(curpath, data)
if len(curpath) == len( data )+1:
mydict[ curpath[0] ] = curpath
return True
return False
def mydraw(data):
global mydict
global mypoints
mydict={}
mypoints=[]
for item in data:
line = list(item)
point1 = (line[0],line[1])
point2 = (line[2],line[3])
if point1 not in mypoints:
mypoints.append( point1 )
if point2 not in mypoints:
mypoints.append( point2 )
#print( "mypoints",mypoints)
for item in mypoints:
curpath = [ item ]
findNextPoint(curpath, data)
#print( "mydict",mydict)
result =[]
for item in mypoints:
if len( mydict[item] ) == len(data)+1:
print( mydict[item] )
return mydict[item]
print([])
return []
def draw(data):
mydraw({(1,1,2,2),(2,1,2,2),(2,1,3,2),(2,1,3,1),(1,1,0,2),(1,1,0,0),(3,2,3,1),(0,0,0,2)})
return mydraw(data)
Created at: 2016/03/25 11:46; Updated at: 2016/03/25 11:46