Two stack sorting
JavaScript (ES6), 23 bytes
Uses 1-indexed cards and stacks. The initial stack is the 1st one. The single-card stack is the 3rd one. Expects \$0\$ for an empty stack.
Returns a 2-digit number, where the 1st digit is the source stack and the 2nd digit is the destination stack.
(a,b,c)=>c?b>c?21:32:13
Try it online!
Commented
( // input:
a, // a = top card in the primary stack
b, // b = top card in the secondary stack
c // c = card in the temporary stack
) => //
c ? // if there's already a card in the temporary stack:
b > c ? // if there's a card in the secondary stack and it's
// greater than the temporary card:
21 // move from secondary to primary
: // else:
32 // move from temporary to secondary
: // else:
13 // move from primary to temporary
Jelly, 9 8 bytes
ṖM⁸aḢ;‘$
Try it online!
A monadic link taking a list of three integers representing the top of the three stacks, or zero for an empty stack. The three stacks are [single card, destination, source]
. Returns a pair of integers indicating which stack to move from and to. In keeping with Jelly’s indexing of lists, the third stack can be referred to either as 3
or 0
.
Inspiration taken from @Arnauld’s JavaScript answer so be sure to upvote that one!
Explanation
Ṗ | Remove last list item
M | Indices of maximum
⁸a | Original argument and with this
Ḣ | Head
;‘$ | Concatenate to itself plus 1