Last answered:

24 Nov 2021

Posted on:

22 Nov 2021

0

Tower of Hanoi problem _ Tower "A" is not Empty and Tower "C" has incomplete disk . Please why?

A = [14,13,12,12,11,10,9,8,7,6,5,4,3,2,1]
B = []
C = []



count = 0

def towers_of_hanoi (A,B,C,n):
    global count

if n == 1:
        disk = A.pop()
        C.append(disk)
        count = count + 1
    else:
        towers_of_hanoi (A,C,B,n-1)
        towers_of_hanoi (A,B,C,1)
        towers_of_hanoi (B,A,C,n-1)
    return count

towers_of_hanoi (A,B,C,14)

16383

A

[14]

B

[]

C

[13, 12, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
image

1 answers ( 0 marked as helpful)
Instructor
Posted on:

24 Nov 2021

0

Hey Ashakah,

Thank you for your question!

It appears that list A has the value 12 twice - remove one of them and everything should be in order :)

Kind regards,
365 Hristina

Submit an answer