We have objects that oscillate between two integer points, [l, r]
, at the speed of one unit per time unit, starting at l
on t=0
. You may assume l < r
. For example, if an object oscillates on [3, 6]
, then we have:
t=0 -> 3
t=1 -> 4
t=2 -> 5
t=3 -> 6
t=4 -> 5
t=6 -> 4
t=7 -> 3
t=8 -> 4
Etc. But objects oscillate continuously, so we also have t=0.5 -> 3.5
and t=3.7 -> 5.3
.
Given two objects oscillating between [l1, r1]
, [l2, r2]
, determine if there is ever a time t
such that the two objects share the same position. You make take l1, r1, l2, r2
in any convenient format, and output any truthy/falsy values.
Truthy inputs:
[[3, 6], [3, 6]]
[[3, 6], [4, 8]]
[[0, 2], [2, 3]]
[[0, 3], [2, 4]]
[[7, 9], [8, 9]]
Falsy inputs:
[[0, 3], [3, 5]]
[[0, 2], [2, 4]]
[[5, 8], [9, 10]]
[[6, 9], [1, 2]]
[[1, 3], [2, 6]]
0
and truthy any positive integer or must they be consistent. Even more, can falsy be the empty list and truthy be any non-empty list? \$\endgroup\$ – Mr. Xcoder Oct 23 '17 at 17:10[[1,3],[2,6]]
: this falsifies the heuristic "the intervals overlap and are not the same length". \$\endgroup\$ – Misha Lavrov Oct 23 '17 at 20:32