data-structures · intermediate · ~15 min
Count the minimum moves recursively.
Implement:
long long hanoi_moves(int n);
Return the minimum number of moves to solve the Tower of Hanoi with n disks, computed recursively. 0 <= n <= 62.
n in [0,62].
Minimum moves (2^n - 1).
Use long long.
#include <stddef.h>
/* Minimum number of moves to solve Tower of Hanoi with n disks (recursively). 0<=n<=62. */
long long hanoi_moves(int n){ (void)n; return 0; }
Forgetting the +1 for moving the largest disk.
0 disks need 0 moves.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.