Problem 196310 · hard · Phase 01 Prerequisites & Setup

Two Garden Plots

conditionals · boolean logic · functions

A city map marks garden plots as rectangles with sides parallel to the axes. Each plot is given as a list [x1, y1, x2, y2] holding two opposite corners, in any order (so [4, 0, 1, 3] and [1, 3, 4, 0] describe the same plot). Write plot_relation(p, q) that returns one word:

  • "same": the two plots are identical.
  • "inside": p lies entirely within q (sides may touch) and they are not the same.
  • "contains": q lies entirely within p (sides may touch) and they are not the same.
  • "overlap": otherwise, the plots share some area (their overlap has positive width and height).
  • "edge": they share no area but touch along a line segment of positive length.
  • "corner": they touch at exactly one point.
  • "apart": they do not touch at all.

Examples

Input:  p = [0, 0, 4, 3], q = [4, 1, 6, 5]
Output: "edge"

Input:  p = [5, 5, 3, 3], q = [3, 5, 1, 7]
Output: "corner"

Input:  p = [0, 0, 10, 10], q = [10, 0, 2, 4]
Output: "contains"

Constraints

  • all coordinates are integers with absolute value at most 10**6
  • every plot has non-zero width and non-zero height

Goals

  • Normalise input before comparing it
  • Separate strict and non-strict comparisons
  • Order six overlapping cases so each is reported exactly once
Starting Python…