Number of ways to reflect a beam in a grid.

44 Views Asked by At

Given a rectangular grid of $n*m$ and co-ordinates of two points $a$ and $b$ we need to find the number of directions we can send a beam from $a$ such that it passes through $b$ and doesn't travel more than distance than $k$ units? It follows normal laws of reflection and reflection occurs at the edges of the rectangle.