Editor

Inside the Rectangle

#219 · Geometry · Beginner · 30 XP · about 6 min

A delivery drone may only land inside a rectangular safe zone whose sides run parallel to the x and y axes. The zone is given by two opposite corners, corner1 and corner2, each an (x, y) tuple of integers. They can be either pair of opposite corners, in either order: bottom-left and top-right, top-left and bottom-right, or the same pairs the other way round.

Write in_rectangle(point, corner1, corner2) that returns True if the landing spot point (an (x, y) tuple of integers) is inside the zone or on its edge, and False otherwise.

Examples

in_rectangle((3, 4), (1, 1), (6, 5))   # returns True
in_rectangle((6, 2), (1, 1), (6, 5))   # returns True
in_rectangle((0, 3), (1, 1), (6, 5))   # returns False
in_rectangle((2, 2), (4, 0), (0, 3))   # returns True

The second spot lies on the right edge, which counts as inside. In the last example the corners are the bottom-right corner (4, 0) and the top-left corner (0, 3).

Note

A zone can be flat: when the two corners share their x or their y value, the zone is a line segment (or a single point when the corners are equal), and only points on it count.

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.