Skip to content

Commit 87e2609

Browse files
a2937gikf
andauthored
fix(curriculum): update step 46 hanoi tower comment (freeCodeCamp#58172)
Co-authored-by: Krzysztof G. <[email protected]>
1 parent 7958384 commit 87e2609

File tree

1 file changed

+36
-1
lines changed
  • curriculum/challenges/english/07-scientific-computing-with-python/learn-recursion-by-solving-the-tower-of-hanoi-puzzle

1 file changed

+36
-1
lines changed

curriculum/challenges/english/07-scientific-computing-with-python/learn-recursion-by-solving-the-tower-of-hanoi-puzzle/64df45a3ad4f8719e5355244.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,42 @@ For now, each recursive call prints the `rods` dictionary without performing any
1616
You should remove the last element from the `rods[source]` list and append it to the `rods[target]` list before the `print` call.
1717

1818
```js
19-
({ test: () => assert.match(code, /move\(\s*n\s*-\s*1\s*,\s*source\s*,\s*auxiliary\s*,\s*target\s*\)\s+rods\s*\[\s*target\s*\]\s*\.append\(\s*rods\s*\[\s*source\s*\]\s*\.pop\(\s*\)\s*\)/) })
19+
({ test: () => assert.isTrue(runPython(`
20+
_log = []
21+
def capture_print(*args):
22+
_log.append(repr(args))
23+
24+
old_print = print
25+
print = capture_print
26+
27+
old_rods = rods
28+
rods2 = {
29+
'A': list(range(5, 0, -1)),
30+
'B': [],
31+
'C': []
32+
}
33+
rods = rods2
34+
35+
move(5, 'A', 'B', 'C')
36+
rods = old_rods
37+
print = old_print
38+
39+
_expected_prints = [
40+
r"({'A': [5, 4, 3, 2], 'B': [], 'C': [1]}, '\\n')",
41+
r"({'A': [5, 4, 3], 'B': [], 'C': [1, 2]}, '\\n')",
42+
r"({'A': [5, 4], 'B': [], 'C': [1, 2, 3]}, '\\n')",
43+
r"({'A': [5], 'B': [], 'C': [1, 2, 3, 4]}, '\\n')",
44+
r"({'A': [], 'B': [], 'C': [1, 2, 3, 4, 5]}, '\\n')",
45+
]
46+
47+
for args in _log:
48+
if not _expected_prints:
49+
break
50+
if args == _expected_prints[0]:
51+
_expected_prints.pop(0)
52+
53+
not rods2['A'] and rods2['C'] == list(range(1, 6)) and not _expected_prints
54+
`))})
2055
```
2156

2257
# --seed--

0 commit comments

Comments
 (0)