8
This problem (see below) has been given as a High School Programming League code golf challenge. The shortest codes submitted during the contest were: 177 bytes in Ruby, 212 bytes in Python 2.5, 265 bytes in C. Can anyone make it shorter? Other programming languages are also allowed.
Problem formulation: Given 8 integers: -1000 < x1, y1, x2, y2, x3, y3, x4, y4 < 1000. Check what is the shape of the intersection of two axis-aligned rectangles: P1 = (x1, y1), (x1, y2), (x2, y2), (x2, y1) and P2 = (x3, y3), (x3, y4), (x4, y4), (x4, y3).
* If the rectangles do not intersect print *nothing*.
* If there is exactly one point in common print *point*.
* If the intersections of P1 and P2 is a line segment print *line*.
* If they have a rectangular area in common print *rectangle*.
Input data specification: The first line contains the number of test cases t (1<=t<1000). Each of the following t lines contains 8 integers: x1, y1, x2, y2, x3, y3, x4, y4 (The area of both rectangles is greater than 0).
You can test your solution here.
What if the coordinates don't make rectangles? What if the shapes overlap to form a shape other than a rectangle? – 0WJYxW9FMN – 2017-01-02T14:30:43.663
@J843136028 you can assume that they do form a rectangle. To the second part off the question I can see now that it is not mentioned that rectangles are axis-aligned (missing word added). – kuszi – 2017-01-03T14:57:13.417
How come I don't see any submitted solutions to this problem? – Keith Randall – 2011-03-12T06:29:25.563
@Keith Randall The contest session is over, results for submitted solutions are summarized here
– kuszi – 2011-03-12T10:55:06.283