Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short backwards DFS solution in Clear category for One line Drawing by StefanPochmann
def draw(segments):
edges = [{s[:2], s[2:]} for s in segments]
nodes = [u for edge in edges for u in edge]
odds = {u for u in nodes if nodes.count(u) % 2}
def dfs(u):
for v in nodes:
if {u, v} in edges:
edges.remove({u, v})
dfs(v)
path.append(u)
path = []
if len(odds) < 4:
dfs(min(odds or nodes))
return path
April 27, 2015
Comments: