Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Interesting, intersecting by dig
from collections import namedtuple
def squares_intersect(s1: tuple[int, int, int], s2: tuple[int, int, int]) -> bool:
# your code here
x, y, length = s2
_range = namedtuple('range', ['x1', 'x2'])
Point = namedtuple('point', ['x', 'y'])
horitzontal = _range(s1[0], s1[0] + s1[2])
vertical = _range(s1[1], s1[1] + s1[2])
bottom_left = Point(x, y)
bottom_right = Point(x + length, y)
top_left = Point(x, y + length)
top_right = Point(x + length, y)
vertices = [bottom_left, bottom_right, top_left, top_right]
return any(horitzontal.x1 <= x <= horitzontal.x2 and vertical.x1 <= y <= vertical.x2 for x, y in vertices )
return False
print("Example:")
print(squares_intersect((2, 2, 3), (5, 5, 2)))
# These "asserts" are used for self-checking
assert squares_intersect((2, 2, 3), (5, 5, 2)) == True
assert squares_intersect((3, 6, 1), (8, 3, 5)) == False
assert squares_intersect((3000, 6000, 1000), (8000, 3000, 5000)) == False
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 11, 2023
Comments: