The Ulam problem of optimal motion of line segments