Tell us what’s happening:
Describe your issue in detail here.
The conditionals you wrote previously are only valid for odd numbers of disks.
Add a nested if
to execute when n
is odd, and add one indent level to your print()
and make_allowed_move()
calls.
I’m stuck to this step, i have to check if the number of disk are odd but the code don’t pass.
Your code so far
NUMBER_OF_DISKS = 4
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, '\n')
for i in range(number_of_moves):
remainder = (i + 1) % 3
if remainder == 1:
if (n % 2 != 0) :
print(f'Move {i + 1} allowed between {source} and {target}')
make_allowed_move(source, target)
### Challenge Information:
Learn Recursion by Solving the Tower of Hanoi Puzzle - Step 38
https://www.freecodecamp.org/learn/scientific-computing-with-python/learn-recursion-by-solving-the-tower-of-hanoi-puzzle/step-38