Loading...
Loading...
Loading...
Move n discs from peg A to peg C using peg B as a helper, one disc at a time, never putting a larger disc on a smaller one. Print the number of moves, then each move as the two pegs, for example A C.
Example
Input
2
Output
3 A B A C B C
Three moves.
Try the problem first. Open one hint at a time.
To move n discs: move n - 1 discs to the helper, move the biggest disc, then move the n - 1 discs onto it.
Collect the moves in a list so you can print the count first.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor