public static int moves(int n) {
if (n == 0) return 0;
return 2 * moves(n - 1) + 1;
}
// call: moves(5)Minimum moves for 5 disks?
- Acheck_circle
31
- B
16
- C
32
- D
25
Explanation
2^5 - 1 = 31 moves.
AP Computer Science A· difficulty 3/5
public static int moves(int n) {
if (n == 0) return 0;
return 2 * moves(n - 1) + 1;
}
// call: moves(5)Minimum moves for 5 disks?
31
16
32
25
Explanation
2^5 - 1 = 31 moves.
Want 10 more like this — adaptive to your weak spots?