Hack Forums
help with recursion? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Coders Lounge (https://hackforums.net/forumdisplay.php?fid=5)
+---- Thread: help with recursion? (/showthread.php?tid=5564206)



help with recursion? - paradox_ - Mar 1, 2017

i need some help with shortest path recursion.
a recursive function is given a and b (makes a rectangle) and the function returns how many different ways the character can move from tile to tile to reach the end goal.

what i'm having trouble with:
-the shortest path is always a+b - 1. how is this important?
-how would my recursion function know if a certain path is already counted?
-how does the recursion function keep track of how many different paths if it has to change the value of a and b to get to the end goal?

i'm probably looking at this wrong but if someone can point me to the right direction i can do all the work. i just don't understand what the relationships are.


* - Hash G. - Mar 1, 2017

If you don't have a defined prototype and work with a language which have some concepts of abstraction, you could just add a variable to the prototype and store paths there.

If you do have a defined prototype, I think I''m either missing something or I lack information to help you.


* - severos - Mar 1, 2017

I'll suggest you take a look at recursive descent algorithm, it's used in parsing code, however same concept can be used for various stuff.
Also you could use graphs and their algorithms too bad I don't remember any right now to name them.