Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
12-liner: clean by stack solution in Clear category for One line Drawing by przemyslaw.daniel
def draw(segments):
points = sum([(x[:2], x[2:]) for x in segments], ())
odds = sum(points.count(x) % 2 for x in set(points))
stack = [([x], segments) for x in points]*(odds < 4)
while stack:
used, left = stack.pop()
if not left: return used
for p in points:
a, b = used[-1]+p, p+used[-1]
stack += [(used+[p], left-{a})]*(a in left)
stack += [(used+[p], left-{b})]*(b in left)
return []
Dec. 26, 2017