Intersection (2) X79913


Statement
 

pdf   zip

html

Let a, b, c, d be integers such that ab and cd. Write a function intersection2(a, b, c, d) that computes the intersection of intervals [a, b] and [c, d]. When the intersection is non empty the function has to return tuple (True, p, q) where integers p and q are such that [p, q] = [a, b] ∩ [c, d] . If the intersection is empty, the function must return tuple (False, 1, 0)

Sample session
>>> intersection2(1, 5, 6, 7)
(False, 1, 0)
>>> intersection2(10, 16, 12, 15)
(True, 12, 15)
>>> intersection2(3, 5, 2, 11)
(True, 3, 5)
>>> intersection2(1, 4, 4, 6)
(True, 4, 4)
Information
Author
ProAl
Language
English
Official solutions
Python
User solutions
Python