Intersection (2) X79913


Statement
 

pdf   zip

Let a,b,c,da, b, c, d be integers such that aba\le b and cdc\le d. Write a function @intersection2(a, b, c, d)@ that computes the intersection of intervals [a,b][a, b] and [c,d][c, d]. When the intersection is non empty the function has to return tuple (𝑇𝑟𝑢𝑒,p,q)(\mathit{True}, p, q) where integers pp and qq are such that [p,q]=[a,b][c,d][p, q] = [a, b] \cap [c, d]. If the intersection is empty, the function must return tuple (𝐹𝑎𝑙𝑠𝑒,1,0)(\mathit{False}, 1, 0)

Sample session

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