If $$A = (0, a_1, \ldots, a_{n-1})$$ is a tuple of $$n$$ points on a line segment in increasing order ($$0 <  a_1 < \cdots < a_{n-1}$$), then $$\Delta A$$ denotes the collection of all pairwise distances between points in $$A$$. For example, if \[A = (0, 2, 4, 7)\] then \[ \Delta A = (7, 5, 4, 3, 2, 2, 0, 0, 0, 0, 2, 2, 3, 4, 5, 7) \] The turnpike problem asks us to reconstruct $$A$$ from $$\Delta A$$.

Assignment

Write a function turnpike that takes a collection (a list or a tuple) of integers $$L$$. The function must return a set containing all tuples of integers $$A = (0, a_1, \ldots, a_{n-1})$$ with $$0 <  a_1 < \cdots < a_{n-1}$$ such that $$\Delta A = L$$.

Example

>>> turnpike((-10, -8, -7, -6, -5, -4, -3, -3, -2, -2, 0, 0, 0, 0, 0, 2, 2, 3, 3, 4, 5, 6, 7, 8, 10))
{(0, 2, 4, 7, 10), (0, 3, 6, 8, 10)}

Resources