15
1
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]]
so it's a pointy wave not a sinusoid, right? – HyperNeutrino – 2017-10-23T16:40:03.463
For reference this challenge refer to this game, where you have to detect if it is possible to jump from one block to the other.
– user202729 – 2017-10-23T16:42:25.103@HyperNeutrino Correct. – orlp – 2017-10-23T16:49:24.590
Can the falsy value be
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? – Mr. Xcoder – 2017-10-23T17:10:33.020@Mr.Xcoder Both of those seem fine to me. – orlp – 2017-10-23T17:13:21.263
3A good falsy test is
[[1,3],[2,6]]
: this falsifies the heuristic "the intervals overlap and are not the same length". – Misha Lavrov – 2017-10-23T20:32:26.867