Exemplo n.º 1
0
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))))
Exemplo n.º 2
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
Exemplo n.º 3
0
def test_11a_example():
    state = (0, A.parse(example))
    moves = A.search(state)
    assert len(moves) == 11
Exemplo n.º 4
0
def test_11a_apply_move():
    state1 = (0, A.parse(example))
    state2 = A.apply_move((+1, [1]), *state1)
    assert state2 == (1, ((3, ), (-1, 1), (-3, ), ()))
Exemplo n.º 5
0
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])]
Exemplo n.º 6
0
def test_11a_example_parser():
    assert A.parse(example) == ((1, 3), (-1, ), (-3, ), ())