• + 3 comments

    This problem can be solved purely mathematically, without any iteration.

    Assume that there exists some k number of jumps, at which they will meet:
    x1 + k(v1) = x2 + k(v2)

    Solving for k:
    k = (x2 - x1) / (v1 - v2)

    If k would be a positive integer, they will land at the same location in k jumps.

    (Note: If k is negative, they would have to hop backwards. If k is not an integer, they will pass eachother while in the air.)

    So you just need to evaluate if that function would result in a positive integer. You don't even need to actually determine a value for k. And no iteration is required.

    The code for this is left as an exercise for the reader.