MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

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)

63 correct solutions
43 incorrect solutions

Last solution submitted on Jan 19, 2015

3 players like this problem

1 Comment

David Young
on 22 Feb 2012

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.

1 Comment

@bmtran
on 1 Feb 2012

no bonus points for me :(

1 Comment