Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Bool operators solution in Speedy category for Interesting, intersecting by Serg900vd
def squares_intersect(s1: tuple[int, int, int], s2: tuple[int, int, int]) -> bool:
'''
If the projections of the squares on the x or y axis do not intersect, then the squares do not intersect.
'''
s1x, s1y, s1l, s2x, s2y, s2l = s1 + s2
return not (((s1x < s2x) and (s1x + s1l < s2x))\
or ((s1x > s2x + s2l) and (s1x + s1l > s2x + s2l))\
or ((s1y < s2y) and (s1y + s1l < s2y))\
or ((s1y > s2y + s2l) and (s1y + s1l > s2y + s2l)))
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 20, 2023
Comments: