Created
April 29, 2021 15:13
-
-
Save andersondanilo/efac5d65bb5245ae8fb1b850a939d237 to your computer and use it in GitHub Desktop.
range intersection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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