Back to Freecodecamp

Step 48

curriculum/challenges/english/blocks/learn-recursion-by-solving-the-tower-of-hanoi-puzzle/64e340302bd28513f3e73740.md

latest962 B
Original Source

--description--

Now, change the comment above the print() call into display our progress.

--hints--

You should change # display starting configuration into # display our progress.

js
({ test: () => assert.match(code, /\)\s+#\s*display\sour\sprogress\s+(?=print\()/) })

--seed--

--seed-contents--

py
NUMBER_OF_DISKS = 4
rods = {
    'A': list(range(NUMBER_OF_DISKS, 0, -1)),
    'B': [],
    'C': []
}

--fcc-editable-region--
def move(n, source, auxiliary, target):
    if n > 0:
        # move n - 1 disks from source to auxiliary, so they are out of the way
        move(n - 1, source, auxiliary, target)
        
        # move the nth disk from source to target
        rods[target].append(rods[source].pop())
        
        # display starting configuration
        print(rods, '\n')
              
--fcc-editable-region--
# initiate call from source A to target C with auxiliary B
move(NUMBER_OF_DISKS, 'A', 'B', 'C')