Skip to content

Instantly share code, notes, and snippets.

@andersondanilo
Created April 29, 2021 15:13
Show Gist options
  • Save andersondanilo/efac5d65bb5245ae8fb1b850a939d237 to your computer and use it in GitHub Desktop.
Save andersondanilo/efac5d65bb5245ae8fb1b850a939d237 to your computer and use it in GitHub Desktop.
range intersection
def inter(range1, range2):
return range2[1] >= range1[0] and range2[0] <= range1[1]
testcases = [
(True, [1, 10], [5, 6]),
(True, [5, 5], [5, 5]),
(True, [1, 5], [5, 10]),
(False, [1, 5], [6, 10]),
]
for testc in testcases:
expected, range1, range2 = testc
print("expected %s = %s " % (expected, inter(range1, range2)))
print("expected %s = %s " % (expected, inter(range2, range1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment