A fly moves following a predefined sequence of discrete jumps (defined by the vectors dx and dy) repeating the same sequence over and over (note that after each sequence of movements the fly may or may not be at the same position where it started).
The fly always starts at the coordinates (0,0) and your job is to determine whether it will ever reach a target coordinate ( x , y ).
note: dx and dy are always equal-sized row vectors and x and y are always scalars. Your function should return true if the trajectory passes through the target.
Example
dx = [0,1,0,-1];
dy = [1,0,1,0];
x = 1;
y = 5;
The fly follows the trajectory:
(0,0) (0,1) (1,1) (1,2) (0,2) (0,3) (1,3) (1,4) (0,4) (0,5) (1,5) (1,6) ...
The trajectory passes through the target point (1,5) so the function should return true.
note: in the test suite, if the target is reachable it will be reachable in at most 100 repetitions of the movement sequence. You get unscored bonus points if your solution does not require this limit to be relatively small (i.e. if the algorithm computational time does not increase linearly with the number of repetitions)
Flawed solution (same flaw as Solution 1327329).
This is an incorrect solution. For example, suppose dx = [0,1,0,-1], dy = [2,0,2,0], x = 1 and y = 5 (which is the same situation as test #1 but with a slightly different dy); then this code would return 'True' when in fact the correct answer would obviously be 'False'.
[Based on solution 1227987] Although this solution passes the test suite, it (and several others like it) is an incorrect solution. For example, suppose dx = [-1,-1,-1,2,-1,6], dy = [-1,-2,-3,1,1,-1], x = 53 and y = -71 (which is the same situation as test #5 but with a slightly different dy); then this code would return 'True' when in fact the correct answer is 'False'.
I still don't understand the scoring system I guess.
Seems odd to me that the commented solution had size 43 ... but doing extra computation reduced this solution to size 33.
(unless JIT is at the level to implicitly convert?)
Although this has passed the tests, I don't think it is correct, since it allows the fly to go backwards in time as well as forwards.
no bonus points for me :(
6421 Solvers
221 Solvers
Omit columns averages from a matrix
492 Solvers
Vectorizing, too easy or too hard?
119 Solvers
Basics: 'Find the eigenvalues of given matrix
270 Solvers