Interesting, intersecting
def squares_intersect(s1, s2):
A square on the two-dimensional plane can be defined as a tuple (x, y, r) where (x, y) are the coordinates of its bottom left corner and r is the length of the side of the square. Given two squares as tuples (x1, y1, r1) and (x2, y2, r2), this function should determine whether these two squares intersect, that is, their areas have at least one point in common, even if that one
point is merely the shared corner point when these two squares are placed kitty corner. This function should not contain any loops or list comprehensions of any kind, but should compute the result using only integer comparisons and conditional statements.
This problem showcases an idea that comes up with some problems of this nature; it is actually far easier to determine that the two squares do not intersect, and negate that answer. Two squares do not intersect if one of them ends in the horizontal direction before the other one begins, or if the
same thing happens in the vertical direction. (This technique generalizes from rectangles lying on the flat two-dimensional plane to not only three-dimensional cuboids, but to hyper-boxes of
arbitrary high dimensions.)
Extracted text: s1 s2 Expected result (2, 2, 3) (5, 5, 2) True ( 3, 6, 1) ( 8, 3, 5) False (8, 3, 3) (9, 6, 8) True (5, 4, 8) (3, 5, 5) True (10, 6, 2) (3, 10, 7) False (3000, 6000, 1000) (8000, 3000, 5000) False (5*10**6, 4*10**6, 8*10**6) (3*10**6, 5*10**6, 5*10**6) True