Skip to content

Instantly share code, notes, and snippets.

@nikhilRP
Created August 5, 2015 18:40
Show Gist options
  • Save nikhilRP/91b762ebac8795f8fb05 to your computer and use it in GitHub Desktop.
Save nikhilRP/91b762ebac8795f8fb05 to your computer and use it in GitHub Desktop.
test_data = [(50, 150), (100, 200), (150, 250), (99, 201), (100, 201), (201, 300), (98, 99)]
def main():
# view region
start = 100
end = 200
print "View region: start - " + str(start) + " end - " + str(end)
print "Method 1 - Nikhil"
for data in test_data:
if data[1] >= start and data[0] <= end:
print str(data) + " overlaps"
else:
print str(data) + " doesn't overlap"
print
print "Method 2 - Frank and Eric"
for data in test_data:
if (start <= data[0] and end > data[0]) or (start < data[1] and end >= data[1]):
print str(data) + " overlaps"
else:
print str(data) + " doesn't overlap"
if __name__ == '__main__':
main()
@nikhilRP
Copy link
Author

nikhilRP commented Aug 5, 2015

View region: start - 100 end - 200
Method 1 - Nikhil
(50, 150) overlaps
(100, 200) overlaps
(150, 250) overlaps
(99, 201) overlaps
(100, 201) overlaps
(201, 300) doesn't overlap
(98, 99) doesn't overlap

Method 2 - Frank and Eric
(50, 150) overlaps
(100, 200) overlaps
(150, 250) overlaps
(99, 201) doesn't overlap
(100, 201) overlaps
(201, 300) doesn't overlap
(98, 99) doesn't overlap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment