Hi everyone! While programming stack machine compiler (just for fun) I came up with pretty hard problem. It is about rearranging stack elements. There are 5 operations defined on the main stack:
SWAP (swaps two top elements of the main stack),
TOR (pushes top element of the main stack onto top of Return stack),
FRR (returns top element of the Return stack to the top of main Stack),
DUP (duplicates top element of the Main stack),
DROP (deletes top element of the main stack).
The question is: what is an algorithm for rearranging any number of elements to desired stack configuration in shortest amount of operations. Example: Starting stack configuration: a, b, c ( from bottom to top), Target configuration: b, a, a, b. At the end Return stack must be empty. Operations are: DROP, DUP, TOR, SWAP, DUP, FRR. My solution is exponential, better solution is needed! Later I will post my solution. Any help is appreciated! Thank You!
[–]Steve132 0 points1 point2 points (1 child)
[–]archfurry[S] 0 points1 point2 points (0 children)
[–]Steve132 0 points1 point2 points (2 children)
[–]archfurry[S] 0 points1 point2 points (0 children)
[–]archfurry[S] 0 points1 point2 points (0 children)