I came across this problem in a recent interview.
We are given a chessboard considered in coordinate plane with origin at leftmost lower corner and leftmost lower corner is black coloured. Each cell of board has width and height $l$ and we are at point $P(x,y)$. We move in steps $(dx, dy)$ i.e. $(x,y) => (x+dx,y+dy)$. Given the value of $x, y, dx, dy$ and $l$, We need to find minimum value of k for which $(x+kdx,y+kdy)$ will lie in white cell. Each value, x, y, dx, dy, l are integers.
I think we need to do it by concept of gcd. But, I am not able to do maths to reach upto solution. How to solve such problem ? Thanks in advance.
First, to simplify the algebraic expressions, assume that all distances have been divided by $l$. (So, in the working below, the $x$ represents your $\frac{x}{l}$) .
Let $x=U+X$ and $y=V+Y$ where $U$ and $V$ are the whole number parts of $x$ and $y$, respectively. If the difference between $U$ and $V$ is odd, then you are already in a white square. So suppose the difference is even.
To get to a white square, the minimum $|k|$ will then be the least of $$\frac{X}{dx},\frac{1-X}{dx},\frac{Y}{dy},\frac{1-Y}{dy}.$$
Returning to your initial variables these quantities are
$$\frac{X}{dx},\frac{l-X}{dx},\frac{Y}{dy},\frac{l-Y}{dy}.$$