Do They Intersect? X52569


Statement
 

pdf   zip   main.py

html

Let a, b, c, d be integers such that ab and cd. Write a function do_they_intersect(a, b, c, d) that tells us whether the open intervals (a, b) and (c, d) have a nonempty intersection.

Observation

Only the function will be evaluated. If your submission includes a main program (e.g. with testmod), it must be either commented out or inside a condition if __name__ == ’__main__’

Sample session
>>> do_they_intersect(1, 5, 3, 7)
True
>>> do_they_intersect(10, 15, 1, 5)
False
>>> do_they_intersect(3, 5, 2, 11)
True
>>> do_they_intersect(1, 4, 4, 5)
False
>>> do_they_intersect(10, 10, 9, 11)
False
>>> not do_they_intersect(2, 3, 1, 2)
True
Information
Author
Jordi Delgado and José Luis Balcázar
Language
English
Official solutions
Python
User solutions
Python