One line Drawing One line Drawing
English FR RU

“The line that describes the beautiful is elliptical. It has simplicity and constant change. It cannot be described by a compass, and it changes direction at every one of its points.”

Rudolf Arnheim

Leonardo da Vinci, Raphael, Michelangelo, Albrecht Dürer, M.C. Escher, Hans Holbein, Paul Klee, LeRoy Neiman. All of these famous artists were left handed.

Our Robots have been spending some time researching the great artists from the Human civilization and would like to learn some of the fundamentals of art. For their first lesson, they need to learn to control their left hand-manipulators well enough to make smooth motions. For this exercise, they have decided to draw various figures on graph paper with an extra challenge rule -- don't lift your pen.

A figure is represented as a set of segments in the rectangular coordinate system. Each segment is represented as a sequence of 4 numbers: (x1, y1, x2, y2), where x1, y1 are coordinates for the first end and x2, y2 -- for the second. Segments are undirected. All points in a figure are connected, so you can reach each point from any point.

You should find a path in order to draw the figure. You can pass through each segment only once and are not allowed to lift the pen. The result must be represented as a sequence of points (tuples with coordinates) in the order of how the pen moves to create the drawing. The path may be started and ended at any point. If it's impossible to draw a figure then return an empty sequence. Let's look at some examples:

figures figures

Example 1: the figure is represented as {(1,2,1,5),(1,2,7,2),(1,5,4,7),(4,7,7,5)} and can be two path - ((7,2),(1,2),(1,5),(4,7),(7,5)) or ((7,5),(4,7),(1,5),(1,2),(7,2)).
Example 2: the figure {(1,2,1,5),(1,2,7,2),(1,5,4,7),(4,7,7,5),(7,5,7,2),(1,5,7,2),(7,5,1,2)} can not be drawn with the given rules, so the result is an empty list or tuple.
Example 3: it's like fig.2 but with one more segment (1,5,7,5) and can be drawn several ways. One of them ((7,2),(1,2),(1,5),(4,7),(7,5),(7,2),(1,5),(7,5),(1,2)).

Input: Figure segments as a set of tuples with 4 integers each.

Output: The path as a list or tuple of tuples with 2 integers each.


draw({(1,2,1,5),(1,2,7,2),(1,5,4,7),(4,7,7,5)}) == ((7,2),(1,2),(1,5),(4,7),(7,5))
draw({(1,2,1,5),(1,2,7,2),(1,5,4,7),(4,7,7,5),(7,5,7,2),(1,5,7,2),(7,5,1,2)}) == []
draw({(1,2,1,5),(1,2,7,2),(1,5,4,7),(4,7,7,5),(7,5,7,2),(1,5,7,2),(7,5,1,2),(1,5,7,5)}) == ((7,2),(1,2),(1,5),(4,7),(7,5),(7,2),(1,5),(7,5),(1,2))


How it is used: This mission illustrates the basics of computer generated vector graphics. The same principles may also be applied to AI pathfinding and topological work.

0 < len(segments) < 30
all(all(0 < x < 100 for x in s) for s in segments)