Пример #1
0
def part2():
    ship = Point(0, 0)
    waypt = Point(10, -1)
    for ln in data:
        direc = ln[0]
        dist = int(ln[1:])
        if direc in 'NESW':
            waypt += deltas[direc] * dist
        elif direc in 'L':
            count = dist // 90
            for i in range(count):
                waypt = waypt.left()
        elif direc in 'R':
            count = dist // 90
            for i in range(count):
                waypt = waypt.right()
        elif direc == 'F':
            ship += waypt * dist
        if DEBUG:
            print(ln, ship, waypt)
    return ship.mandist()
Пример #2
0
def part1():
    ship = Point(0, 0)
    facing = deltas['E']
    for ln in data:
        direc = ln[0]
        dist = int(ln[1:])
        if direc in 'NESW':
            ship += deltas[direc] * dist
        elif direc in 'L':
            count = dist // 90
            for i in range(count):
                facing = facing.left()
        elif direc in 'R':
            count = dist // 90
            for i in range(count):
                facing = facing.right()
        elif direc == 'F':
            ship += facing * dist
        if DEBUG:
            print(ln, ship)
    return ship.mandist()