def parse(lines): floors = A.parse(lines) return sorted( tuple((a, b) for ((_, a), (_, b)) in zip( sorted((abs(v), a) for (a, vs) in enumerate(floors) for v in vs if v > 0), sorted((abs(v), b) for (b, vs) in enumerate(floors) for v in vs if v < 0))))
def test_11a_answer(): with open('input/day11.txt', 'r') as f: state = (0, A.parse(f)) moves = A.search(state) assert len(moves) == 47
def test_11a_example(): state = (0, A.parse(example)) moves = A.search(state) assert len(moves) == 11
def test_11a_apply_move(): state1 = (0, A.parse(example)) state2 = A.apply_move((+1, [1]), *state1) assert state2 == (1, ((3, ), (-1, 1), (-3, ), ()))
def test_11a_find_moves(): floors = A.parse(example) moves = A.find_moves(0, floors) assert list(moves) == [(+1, [1, 3]), (+1, [1]), (+1, [3])]
def test_11a_example_parser(): assert A.parse(example) == ((1, 3), (-1, ), (-3, ), ())