How do you find the best set of stack motions that will sort the * known * list?

The problem of sorting unknown lists is known. But what about the problem of finding the optimal sort for a known list in a stacked machine? That is, suppose you have the following stack machine:

[4,1,3,2]
[]
[]

That is, there is a place for 3 stacks, and 1 of them is filled with numbers. Also, suppose your stack machine can do 2 movements: move a b(puts the top element aon b) and join a b(puts the stack aon top of the stack b). In this case, the optimal sorting:

move 0 1
move 0 1
move 0 2
join 1 2
move 0 2

The following sequence will be executed:

[4,1,3,2][4,1,3][4,1][4][4][]
[][2][2,3][2,3][][]
[][][][1][1,2,3][1,2,3,4]

, , ?

+4
1

, , , , , ( ).

:

, . , . , , , , .

, 0. . move , . join unjoin, . , "" "unjoin-operation", 1. , , 2. , , .

, , , . , , - , .

, , - , . , . , .

, 1 ( ) - . 1 , 1 , , .

, , , . , , . , , , , , .

, , : , , , , , . , , . , , . , , .

, , , , . , , , , .

+1

Source: https://habr.com/ru/post/1612133/


All Articles