# String node untying algorithm

Let say that we have four straight string with colors RED, GREEN, BLUE and YELLOW. These strings are tied up randomly. We know the current state of string (like starting point, where we should we start untying from) and the final state (where current string must look like after untying them).

Here is a very simple example of the problem:

At every move, we are allowed to replace only two nearby strings. For example, to solve the shown problem, we should do the following replacements:

1) Replace GREEN and YELLOW

2) Replace BLUE and GREEN

But in a programming environment, how can I calculate the movements to untie the strings? What will be the algorithm specifically to solve such type of problems? Here is another variation of the question. Its not possible to solve this problem according to the answer.