My issue
not able solve the problem please provide hints
My code
import java.util.Scanner;
class CodeChef {
// Update your code below this line
public static void tower_Of_Hanoi(int n, int source, int destination, int auxiliary) {
def tower_of_hanoi(n, source, destination, auxiliary):
if n ==0 :
return
tower_of_hanoi(n-1 , source , auxiliary , destination )
print("Move disk" , n , "from rod" ,source , "to rod" , destination )
tower_of_hanoi( n-1 , auxiliary , destination , source )
def solve_tower_of_hanoi(n):
print(f"Tower of Hanoi solution for {n} disks:")
tower_of_hanoi(n, 1, 3, 2)
print(f"Total number of moves: {2**n - 1}")
n = int(input())
solve_tower_of_hanoi(n)
}
public static void solveTowerOfHanoi(int n) {
System.out.printf("Tower of Hanoi solution for %d disks:%n", n);
towerOfHanoi(n, 1, 3, 2);
System.out.printf("Total number of moves: %d%n", (1 << n) - 1);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
solveTowerOfHanoi(n);
scanner.close();
}
}
Learning course: Design and Analysis of Algorithms
Problem Link: https://www.codechef.com/learn/course/kl-daa/KLDAA2400E/problems/RECUR16