I've got an assignment to make a program (in which you can type the amount of discs) that solves the Towers of Hanoi and draws(prints) every step of the solution.
what i've tried is using a basic recursive code:
def hanoi(n, pocz:list, dopol:list, fin:list):
if n > 0:
hanoi(n-1, pocz, fin, dopol)
fin.insert(0, pocz.pop(0))
print(f'{pier},{drug},{trz}')
hanoi(n-1, dopol, pocz, fin)
pier=[1,2,3,4]
drug=[]
trz=[]
print(f'{pier},{drug},{trz}')
hanoi(t,pier,drug,trz)
which gives me the solution steps in numbers:
[1, 2, 3, 4],[],[]
[2, 3, 4],[1],[]
[3, 4],[1],[2]
[3, 4],[],[1, 2]
. . .
[2],[1],[3, 4]
[],[1],[2, 3, 4]
[],[],[1, 2, 3, 4]
what I need is for the program to output something like this:
what i've tried doing is inserting different algorithms into the middle of the recursion to either make additional lists and work with them later, or using the amount and the number of disks do the printing in the function itself, but they would either mess up the function itself, or get overwritten later on.