Card Stacking is a game on a computer starting with an array of cards labelled .
A stack of cards can be moved by dragging horizontally with the mouse to another stack but only when the resulting stack is in sequence. The goal of the game is to combine the cards into a single stack using minimal total drag distance.
For the given arrangement of 6 cards the minimum total distance is .
For cards, the cards are arranged so that the card at position is .
We define to be the minimal total drag distance to arrange these cards into a single sequence.
For example, when we get the sequence and .
You are given .
Find .
Note: is not defined for all values of .
Write-up coming later
The complete problem is available here. An approach, code, and answer will be added later.