Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
No begin without end solution in Clear category for One line Drawing by Tinus_Trotyl
def connect(begin, segments):
if not segments: return [begin]
for i, segment in enumerate(segments):
if begin in segment:
for a, b in (0, 1), (1, 0):
if begin == segment[a]:
plot = connect(segment[b], segments[:i] + segments[i+1:])
if plot: return [begin] + plot
return []
def draw(segments):
segments = [((i[0],i[1]), (i[2],i[3])) for i in segments]
nodes, edges = set(), dict()
for edge in segments:
nodes = nodes | {edge[0], edge[1]}
for node in tuple(nodes):
edges[node] = []
for segment in segments:
for a, b in (0, 1), (1, 0):
if node == segment[a]:
edges[node].append(segment[b])
outer = []
for node in edges:
if len(edges[node]) % 2 : outer.append(node)
if len(outer) in (0, 2): # if there is a begin point, there must be one end point too !!!
for i, begin in enumerate(segments):
for a, b in (0, 1), (1, 0):
plot = connect(begin[b], segments[:i] + segments[i+1:])
if plot: return [begin[a]] + plot
return []
Oct. 11, 2017