The Sylvester-Gallai theorem says: Suppose you have a finite list of points in the plane. Suppose further that not all of those points are collinear (lie in a single line). Then there is some line containing precisely two of the points. (That is, there's some line on which two of the points lie, but not more than two.)
You task is to find such a line. Note that more than one exists; you need to find one.
Input:
A bunch of points denoted by their Cartesian coordinates. You may assume the coordinates are nonnegative integers, if you like. The string (1,2),(0,4),(5,6)
and the list 1
, 2
, 0
, 4
, 5
, 6
and other formats are fine, and can be function parameters or read from STDIN or whatever.
If you prefer, allow also radical-root input (with positive-integer index). Then, each point will be represented by four numbers: the index and radicand of the abscissa, and the index and radicand of the ordinate. A rational number will be represented with index 1
. Again, the input can be like ((1,2),(3,4)),((6,7),(8,9)),((2,3),(4,5))
or like 1
, 2
, 3
, 4
, 6
, 7
, 8
, 9
, 2
, 3
, 4
, 5
, or what-have-you. You may assume that the radicand is a nonnegative integer.
You may assume the points are distinct from one another and are not all collinear (and thus, in particular, that there are more than two points).
Output:
A line guaranteed by Sylvester-Gallai. This can be presented in any Cartesian-based form that completely specifies the line and allows people to visualize it. (I expect that answers will typically use either the line's slope and a point on it or two points on the line.)
Scoring:
This is a popularity contest. The answer with the greatest number of net votes after about a week will get the checkmark. Everyone can vote at will, obviously, but I, personally, will bear in mind at least these factors: ingenuity of the solution (including avoidance of the brute-force method), explanation of the code, ability to accept radical-root input, and simplicity of the code (in flop count / runtime).