advent/2016/01-1.py
2017-12-12 13:57:20 -08:00

18 lines
434 B
Python

# Python!
import collections
with open('01.txt') as file:
turns = file.read().replace(' ', '').split(',')
moves = collections.defaultdict(int)
direction = collections.deque(['N', 'E', 'S', 'W'])
for turn in turns:
direction.rotate(1 if turn[0] == 'L' else -1)
dist = int(turn[1:])
moves[direction[0]] += dist
vert = abs(moves['N'] - moves['S'])
hor = abs(moves['E'] - moves['W'])
print('Distance in blocks:', str(vert + hor))