Skip to content

Commit

Permalink
Added Tower of Hanoi code
Browse files Browse the repository at this point in the history
  • Loading branch information
varshapandiann committed Oct 13, 2024
1 parent 4cad99c commit 5b9c8b7
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Python/tower_of_hanoi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def tower_of_hanoi(n, source, destination, auxiliary):
if n == 1:
print(f"Move disk 1 from {source} to {destination}")
return
tower_of_hanoi(n - 1, source, auxiliary, destination)
print(f"Move disk {n} from {source} to {destination}")
tower_of_hanoi(n - 1, auxiliary, destination, source)

tower_of_hanoi(3, 'A', 'C', 'B')

0 comments on commit 5b9c8b7

Please sign in to comment.