From d2b848f066804ed5bf4ba60fbc05b9aeb823a96a Mon Sep 17 00:00:00 2001 From: Khushi Shroff Date: Fri, 14 Oct 2022 15:08:59 +0530 Subject: [PATCH] created Tower of Hanoi --- Tower of Hanoi.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Tower of Hanoi.py diff --git a/Tower of Hanoi.py b/Tower of Hanoi.py new file mode 100644 index 0000000..412c503 --- /dev/null +++ b/Tower of Hanoi.py @@ -0,0 +1,12 @@ +#Python Program for Tower of Hanoi +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) + +# Driver code +n = 4 +TowerOfHanoi(n,'A','B','C') \ No newline at end of file