Add currently solved exerises from Chapter 16

This commit is contained in:
lolabird 2023-12-20 22:24:30 -07:00
commit 1a90502946
6 changed files with 269 additions and 0 deletions

View file

@ -0,0 +1,28 @@
def stackTowers(num):
A = []
B = []
C = []
rounds = 0
for i in range(num):
A.insert(0, i+1)
def hanoi(num, start, aux, end):
nonlocal rounds
if num == 1:
end += [start.pop()]
rounds += 1
print(rounds, A, B, C)
else:
hanoi(num - 1, start, end, aux)
end += [start.pop()]
rounds += 1
print(rounds, A, B, C)
hanoi(num -1, aux, start, end)
hanoi(num, A, B, C)
stackTowers(5)