Grid Path Counting Puzzle – Looking for a Pure Combinatorics Solution I came across the following interesting grid path problem. Problem A person starts at A and wants to reach B. He can move only Right or Down. He cannot pass through point C. How many valid paths are there?









Auto comment: topic has been updated by abhi_yo (previous revision, new revision, compare).
I guess this can be done by first calculating the number of ways to reach from point A to point B and then subtracting the ways where we came through point C. The number of ways to reach from point A to point B through point C can be calculated as number of ways to reach from point A to point C multiplied by the number of ways to reach from point C to point B.
the number of ways to travel from point X to point Y in a 2D grid can be calculated by standard combinatorics formula
Let the grid dimensions be $$$n$$$ tall and $$$m$$$ wide and the invalid point be $$$(x, y)$$$ where the top left is $$$(1, 1)$$$ and the bottom right is $$$(m, n)$$$
Then the amount of paths is equal to $$$\binom{n+m-2}{n-1} - \binom{x+y-2}{x-1}\binom{m-x+n-y}{n-y}$$$
The proof is left as an exercise to the reader
Enhanced version
you can reframe the problem as ( I'm assuming B is the bottom right corner ) we need to create a string with 'R' and 'D' characters such that there are (columns-1) 'R' and (rows-1) 'D' characters but at any point you are'nt allowed to reach C (let r2 be the row number of point C and c2 be the column number of point C) then you can't have (r2-1) 'D' and (c2-1) 'R' characters in the string prefix we can simply find the answer by subtracting number of such strings from total number of valid strings