On the three paths of a station are A, B, and C types of train cars as shown in the figure.
A locomotive driver (L) can attach from 1 to 9 train cars to a locomotive at any time, move them to the right path, and then return them to any left path.
For example, if the locomotive picks up 2 train cars from track no. 3 to track no. 1, then after such an action, the distribution of train cars along the tracks will be as follows:
- А C B А C
- B C А
We code these actions by one line as: 2 3 1
It is necessary to develop an algorithm for the driver's actions to sort train cars. On each path, the train cars the same type should be (it doesn’t matter which path).
Question 2. It is necessary to show that your solution is the shortest.
Source: vos.olimpiada.ru/ (in Russian).