curriculum/challenges/english/blocks/learn-recursion-by-solving-the-tower-of-hanoi-puzzle/650c6082e5586f9e3acfcd3b.md
Now, delete the rods dictionary and turn its keys into the variables A, B, and C, respectively, keeping their values. Refactor your code to reflect these changes. If you see the output on the terminal, you correctly did this step.
You should turn rods['A'] into a variable named A keeping its value.
assert.match(code, /A\s*=\s*list\s*\(\s*range\s*\(\s*NUMBER_OF_DISKS\s*,\s*0\s*,\s*-\s*1\s*\)\s*\)/);
You should turn rods['B'] into a variable named B keeping its value.
assert.match(code, /B\s*=\s*\[\s*\]/);
You should turn rods['C'] into a variable named C keeping its value.
assert.match(code, /C\s*=\s*\[\s*\]/);
You should modify your print() call to print A, B, C, instead of the rods object. Keep the newline character in the print() call.
assert.match(code, /print\s*\(\s*A\s*,\s*B\s*,\s*C\s*,\s*('|")\\n\1\s*\)/);
You should have target.append(source.pop()) in your code.
assert.match(code, /target\.append\s*\(\s*source\.pop\s*\(\s*\)\s*\)/);
--fcc-editable-region--
NUMBER_OF_DISKS = 4
rods = {
'A': list(range(NUMBER_OF_DISKS, 0, -1)),
'B': [],
'C': []
}
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, target, auxiliary)
# move the nth disk from source to target
rods[target].append(rods[source].pop())
# display our progress
print(rods, '\n')
# move the n - 1 disks that we left on auxiliary onto target
move(n - 1, auxiliary, source, target)
# initiate call from source A to target C with auxiliary B
move(NUMBER_OF_DISKS, 'A', 'B', 'C')
--fcc-editable-region--