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.)

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter1: Getting Started With Excel
Section: Chapter Questions
Problem 1.12CP
icon
Related questions
Question

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.)

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
Transcribed Image 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
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Use of XOR function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage