From 221553a6a8f8b941f551e50bb2b309abc995d9e7 Mon Sep 17 00:00:00 2001 From: Nayana Pardhekar <91368301+nayanapardhekar@users.noreply.github.com> Date: Sat, 30 Oct 2021 23:31:10 +0530 Subject: [PATCH] Tower of Hanoi Created a program for Tower of Hanoi in Python It contributes to #16 --- tower_of_hanoi | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tower_of_hanoi diff --git a/tower_of_hanoi b/tower_of_hanoi new file mode 100644 index 0000000..c57f633 --- /dev/null +++ b/tower_of_hanoi @@ -0,0 +1,14 @@ +# Recursive Python function to solve the 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') +# A, C, B are the name of rods