Back to Freecodecamp

Step 19

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

latest860 B
Original Source

--description--

Now, replace the expression in the if condition with the remainder variable.

--hints--

You should replace (i+ 1) % 3 with the remainder variable.

js
({ test: () => assert.match(code, /^\s{8}if\s+remainder\s*==\s*1\s*:/m) })

--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': []
}

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

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