Ejemplo n.º 1
0
def part_2(cmds):
    ship = Vector(0, 0)
    waypoint = Vector(10, 1)
    for dir, steps in cmds:

        if dir == "F":
            ship += waypoint * steps

        elif dir in NESW_VEC:
            waypoint += NESW_VEC[dir] * steps
        elif dir == "R":
            waypoint = waypoint.rotate_degree(steps)
        elif dir == "L":
            waypoint = waypoint.rotate_degree(-steps)
        else:
            raise Exception(f"Unknown instruction {(dir, steps)}")

    return abs(ship.x) + abs(ship.y)
Ejemplo n.º 2
0
def test_rotation():
    vec = Vector(1, 2)

    assert Vector(2, -1) == vec.rotate_degree(90)
    assert Vector(-1, -2) == vec.rotate_degree(180)
    assert Vector(-2, 1) == vec.rotate_degree(-90)