forked from adnanaziz/EPIJudge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanoi.py
37 lines (27 loc) · 1.26 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
import functools
from typing import List
from test_framework import generic_test
from test_framework.test_failure import TestFailure
from test_framework.test_utils import enable_executor_hook
NUM_PEGS = 3
def compute_tower_hanoi(num_rings: int) -> List[List[int]]:
# TODO - you fill in here.
return []
@enable_executor_hook
def compute_tower_hanoi_wrapper(executor, num_rings):
pegs = [list(reversed(range(1, num_rings + 1)))
] + [[] for _ in range(1, NUM_PEGS)]
result = executor.run(functools.partial(compute_tower_hanoi, num_rings))
for from_peg, to_peg in result:
if pegs[to_peg] and pegs[from_peg][-1] >= pegs[to_peg][-1]:
raise TestFailure('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 TestFailure('Pegs doesn\'t place in the right configuration')
if __name__ == '__main__':
exit(
generic_test.generic_test_main('hanoi.py', 'hanoi.tsv',
compute_tower_hanoi_wrapper))