Checkpoint: tower moves
Challenge on lesson: Checkpoint: moves and plan
CHALLENGE
Difficulty: intermediate+25 XP
Implement int moves(int n): the number of single-disk moves to shift an n-disk tower (the classic recurrence: move n−1 aside, move 1, move n−1 back → moves(n) = 2·moves(n−1) + 1, base moves(0) = 0). Then implement void plan(int n) printing one line per move: "disk k: A->B" style lines for the 3-disk solution is overkill — instead print just the COUNT pattern: plan(n) prints n lines "step i" for i = 1..n. (Both are graded; moves is the recursion, plan is the print-order discipline.)
Press Submit to check your solution.
Back to lesson: Checkpoint: moves and plan