Tower With a Middle Stop
Three pegs stand in a row and are named by the one-letter strings left, middle and right, all different. discs discs of different sizes sit on left, the smallest on top. A move takes the top disc of a peg and puts it on top of a neighbouring peg, so a disc travels between left and middle or between middle and right, never straight between left and right. A disc may never be placed on a smaller disc. Return the shortest sequence of moves that brings every disc from left to right, as a list of two-element lists [from, to] naming the pegs. That sequence has 3 ** discs - 1 moves and is unique. With 0 discs return an empty list.
Recursion is the natural tool: the bottom disc has to stop on the middle peg on its way across, and the discs above it must be moved out of its way before each of its two steps.
For example, discs = 1, left = "L", middle = "M", right = "R" gives [["L", "M"], ["M", "R"]].
Example 1
A single disc cannot jump from L to R, so it stops on M first.
Example 2
The small disc goes to R (via M), the big disc steps to M, the small disc comes back to L (via M), the big disc steps to R, and the small disc crosses again.
Constraints
0 <= discs <= 4, so the answer has at most 80 movesleft,middleandrightare three different uppercase letters
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.