Back to Freecodecamp

Step 45

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

latest960 B
Original Source

--description--

Before your recursive call, add a comment saying move n - 1 disks from source to auxiliary, so they are out of the way.

--hints--

You should add a comment with the provided text before your recursive call.

js
({ test: () => assert.match(code, /if\s+n\s*>\s*0\s*:\s+#\s*move\sn\s-\s1\sdisks\sfrom\ssource\sto\sauxiliary\s*,\s*so\sthey\sare\sout\sof\sthe\sway\s+(?=move\(\s*n\s*-\s*1\s*,\s*source\s*,\s*auxiliary\s*,\s*target\s*\))/) })

--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, source, auxiliary, target)
        
        # 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')