示例#1
0
def main():
    input_ = load_from_file("day12_input.txt")

    init_ship_pos = ShipPosition(x=0, y=0, direction="E")
    instructions = [Instruction(line[:1], int(line[1:])) for line in input_]

    # PART 1
    moves = accumulate(move, instructions, initial=init_ship_pos)
    last_pos_pt1 = last(moves)
    sol_pt1 = abs(last_pos_pt1)
    print(sol_pt1)

    assert sol_pt1 == 441  # Solution for my input

    # PART 2
    init_with_waypoint = CompPosition(init_ship_pos, WaypointPosition(10, 1))
    moves_pt2 = accumulate(move_pt2, instructions, initial=init_with_waypoint)
    last_pos_pt2 = last(moves_pt2)
    sol_pt2 = abs(last_pos_pt2.ship)
    print(sol_pt2)

    assert sol_pt2 == 40014  # Solution for my input
示例#2
0
def test_last():
    assert last('ABCDE') == 'E'
    assert last((3, 2, 1)) == 1
    assert isinstance(last({0: 'zero', 1: 'one'}), int)
示例#3
0
def test_last():
    assert last('ABCDE') == 'E'
    assert last((3, 2, 1)) == 1
    assert isinstance(last({0: 'zero', 1: 'one'}), int)
def test_last():
    assert last("ABCDE") == "E"
    assert last((3, 2, 1)) == 1
    assert isinstance(last({0: "zero", 1: "one"}), int)
示例#5
0
def test_last():
    assert last("ABCDE") == "E"
    assert last((3, 2, 1)) == 1
    assert isinstance(last({0: "zero", 1: "one"}), int)