Hello,
I'm having difficulties returning the right values from a recursive call.
The problem is to check a list of items. Each item can be visited only once, and I want to find every possible path between the items, quite similiar to a TSP.
I've generated a list that includes all the previously visited items. However, when the recursive call returns, this list is remembered. Let me try to illustrate:
List of legal items: a, b, c
First path: a - b - c
Then I want it to go back to b, check the list of visited items, it discovers a and c, and goes to a.
a sees only b, not c, thus goes to c.
c sees that a has been visited, and goes to b.
thus the next path becomes
a - c - b
It would then check b, then c, and a. Since all legal items at a is visited, it turns to b and continues the process from start: b - c - a, b - a - c and soforth.
Unfortunately, the list that included visited items of each recursive layer is returned with all three items.
Please let me know if you understand the problem
I have the (not working) code ready to be pasted in, but i guess it would be quite a long and messy post
Thanks for any suggestions on how to return the right argument
kanskje
I'm having difficulties returning the right values from a recursive call.
The problem is to check a list of items. Each item can be visited only once, and I want to find every possible path between the items, quite similiar to a TSP.
I've generated a list that includes all the previously visited items. However, when the recursive call returns, this list is remembered. Let me try to illustrate:
List of legal items: a, b, c
First path: a - b - c
Then I want it to go back to b, check the list of visited items, it discovers a and c, and goes to a.
a sees only b, not c, thus goes to c.
c sees that a has been visited, and goes to b.
thus the next path becomes
a - c - b
It would then check b, then c, and a. Since all legal items at a is visited, it turns to b and continues the process from start: b - c - a, b - a - c and soforth.
Unfortunately, the list that included visited items of each recursive layer is returned with all three items.
Please let me know if you understand the problem
I have the (not working) code ready to be pasted in, but i guess it would be quite a long and messy post
Thanks for any suggestions on how to return the right argument
kanskje