Back to Freecodecamp

Step 22

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

latest1.3 KB
Original Source

--description--

You wrote the code to find the allowed movement between the rods, but the actual move could be in both directions. After the print() call, declare a variable named forward and set it to False. You will use that variable to check in which direction you need to move the disk between the rods.

--hints--

You should declare a variable named forward.

js
({ test: () => assert.match(code, /forward\s*=\s*./) })

Your forward variable should be set to False.

js
({ test: () => assert.match(code, /forward\s*=\s*False/) })

--seed--

--seed-contents--

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

def move(n, source, auxiliary, target):
    # display starting configuration
    print(rods)
    for i in range(number_of_moves):
        remainder = (i + 1) % 3
--fcc-editable-region--
        if remainder == 1:
            print(f'Move {i + 1} allowed between {source} and {target}')
--fcc-editable-region--
        elif remainder == 2:
            print(f'Move {i + 1} allowed between {source} and {auxiliary}')
        elif remainder == 0:
            print(f'Move {i + 1} allowed between {auxiliary} and {target}')

# initiate call from source A to target C with auxiliary B
move(NUMBER_OF_DISKS, 'A', 'B', 'C')