From f870b9f973127e111fb66dd71c88a5394a0af762 Mon Sep 17 00:00:00 2001 From: NickSahu <4uamystery@gmail.com> Date: Sun, 15 Oct 2023 14:41:58 +0530 Subject: [PATCH] Tower of Hanoi --- TowerOfHanoi | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 TowerOfHanoi diff --git a/TowerOfHanoi b/TowerOfHanoi new file mode 100644 index 0000000..21bb020 --- /dev/null +++ b/TowerOfHanoi @@ -0,0 +1,11 @@ +def tower_of_hanoi(n, source, auxiliary, target): + if n == 1: + print(f"Move disk 1 from {source} to {target}") + return + tower_of_hanoi(n-1, source, target, auxiliary) + print(f"Move disk {n} from {source} to {target}") + tower_of_hanoi(n-1, auxiliary, source, target) + +n = int(input(" Enter number of disks : ")) +tower_of_hanoi(n, 'A', 'B', 'C') +print(" **SOLVED** ")