I am trying to write a recursive function (in C++) to count the number of north-east paths from one point to another in a rectangular grid.
The user enters coordinates of the point A and B, and then the program outputs the number of possible paths between the two points.
I know the basics of a recursive function but i am having trouble with this particular problem.
Does it have to be a recursive function, because there is a simple mathematical formula to solve this problem - it involves basic permutations/combinations knowledge.
Definitely don't need A* for this. It is a simple formula using combinations.
The formula is:
(Total Steps North + Total Steps East)!
--------------------------------------------------
(Total Steps North)! * (Total Steps East)!
For example, if you start at point A(2,1) and are going to point B(6,8), you need to go north by 7 steps (8 - 1 = 7), and east by 4 steps (6 - 2 = 4), for a total of 11 steps. So you just plug it into the formula and get:
11!
--------- = 330 possibilities
7! * 4!
No need for a complicated algorithm or any recursion.