Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the move from source to destination peg.
DSA Rust
println!("Move disk from peg [1] to peg B");
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of peg labels.
Confusing source and destination pegs.
✗ Incorrect
The source peg is labeled "A" in the Tower of Hanoi problem, so the move is from peg "A" to peg B.
2fill in blank
mediumComplete the code to recursively call the function to move n-1 disks.
DSA Rust
hanoi([1] - 1, source, auxiliary, destination);
Attempts:
3 left
💡 Hint
Common Mistakes
Using n instead of n - 1.
Using n + 1 which is incorrect.
✗ Incorrect
To move n-1 disks, we subtract 1 from n in the recursive call.
3fill in blank
hardFix the error in the base case condition to stop recursion when no disks remain.
DSA Rust
if [1] == 0 { return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking pegs instead of number of disks.
Using wrong variable names in condition.
✗ Incorrect
The base case checks if n (number of disks) is zero to stop recursion.
4fill in blank
hardFill both blanks to print the move from source to destination peg correctly.
DSA Rust
println!("Move disk from peg [1] to peg [2]");
Attempts:
3 left
💡 Hint
Common Mistakes
Using string literals instead of variables.
Swapping source and destination.
✗ Incorrect
The move is from the source peg to the destination peg, so print source and destination variables.
5fill in blank
hardFill all four blanks to complete the recursive Tower of Hanoi function call correctly.
DSA Rust
hanoi([1] - 1, [2], [3], [4]);
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up auxiliary and destination pegs.
Using wrong values for n or pegs.
✗ Incorrect
To move n-1 disks from auxiliary to destination using source, call hanoi(n-1, auxiliary, destination, source).
