From f84d109cbe8825070381f3329c65157ea850ab98 Mon Sep 17 00:00:00 2001 From: ParalallHimself <112560813+ParalallHimself@users.noreply.github.com> Date: Wed, 4 Oct 2023 09:38:51 +0530 Subject: [PATCH] Created TowerOfHanoi Python program to solve the tower of hanoi problem recursively. --- ParalallHimself/towerOfHanoi | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ParalallHimself/towerOfHanoi diff --git a/ParalallHimself/towerOfHanoi b/ParalallHimself/towerOfHanoi new file mode 100644 index 0000000..792898d --- /dev/null +++ b/ParalallHimself/towerOfHanoi @@ -0,0 +1,11 @@ +def TowerOfHanoi(n , source, destination, auxiliary): + if n==1: + print ("Move disk 1 from source",source,"to destination",destination) + return + TowerOfHanoi(n-1, source, auxiliary, destination) + print ("Move disk",n,"from source",source,"to destination",destination) + TowerOfHanoi(n-1, auxiliary, destination, source) + +#Taking user input +n= input("Enter the no. of disks") +TowerOfHanoi(n,'A','B','C')