Back to Problem Solutions forum
Hello to everyone! Problem nr.100 should have been solved using recursive function.The main idea to check every possible variant for pedestrian to go at every point. My function actually check couple of variants and suddenly stops in the middle of the process. I have already the cod and all i need is a hint regarding my recursive function. Sure i can not display the cod here due to moral judgement because most of us still have to solve this,but i can show it in private if someone is offering to help me. Thanks!
The problem doesn't have to be solved with recursion (it can, but other methods are possible).
Without any code, it is very difficult to see where you could be going wrong; with recursive method, it is often the stop condition that is incorrect, missing a possibility.
Have you tried stepping through your code with a debugger? Or even printing the state of your recursive function at each call to see how it is progressing?
A good way to test those problems is to create a smaller one (less road and cars) that can be solved "by hand" and then check where to code is failing.
Hope some of this helps...
I done all the staff you suggested(take less roads, looke what happeed inside the function via debug) and probelem is following: let's assume that pedestrian have two possibility 1) to wait one turn and 2) to cross forward one line. So the function will check fisrt option and for exemple is dead point, so everything would come back to the starting point and somehow the function do not want to check the second option and would stop.
Here is my problem and i cannot understand Why :(
You need to modify your function to evaluate all possibilities and then return the most optimistic one; alternatively, modify your function to receive a state and return a list of possibilities, then have the calling code decide what to do with it...
That is right "function to evaluate all possibilities" - This is what my function can not do and i can not understand why, even if ilooked step by step via debug. The only way to help me is to look at my cod :)