forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanoi.py
37 lines (27 loc) · 1.25 KB
/
hanoi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from test_framework.test_failure_exception import TestFailureException
from test_framework.test_utils import enable_timer_hook
NUM_PEGS = 3
def compute_tower_hanoi(num_rings):
# Implement this placeholder.
return []
@enable_timer_hook
def compute_tower_hanoi_wrapper(timer, num_rings):
pegs = [list(reversed(range(1, num_rings + 1)))
] + [[] for _ in range(1, NUM_PEGS)]
timer.start()
result = compute_tower_hanoi(num_rings)
timer.stop()
for from_peg, to_peg in result:
if pegs[to_peg] and pegs[from_peg][-1] >= pegs[to_peg][-1]:
raise TestFailureException("Illegal move from {} to {}".format(
pegs[from_peg][-1], pegs[to_peg][-1]))
pegs[to_peg].append(pegs[from_peg].pop())
expected_pegs1 = [[], [], list(reversed(range(1, num_rings + 1)))]
expected_pegs2 = [[], list(reversed(range(1, num_rings + 1))), []]
if pegs not in (expected_pegs1, expected_pegs2):
raise TestFailureException(
"Pegs doesn't place in the right configuration")
from test_framework import test_utils_generic_main, test_utils
if __name__ == '__main__':
test_utils_generic_main.generic_test_main('hanoi.tsv',
compute_tower_hanoi_wrapper)