Advent of Code 2020, now in the most terse and awful python possible
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

#!/usr/bin/env python3
from sys import argv
i = [(x[0], int(x[1:].strip())) for x in open(argv[1])]
v = (0,0,0)
for d in i:
if d[0] == "F":
dv = [(1,0), (0,-1), (-1,0), (0,1)][(v[2]//90)%4]
v = (v[0]+dv[0]*d[1],v[1]+dv[1]*d[1],v[2])
continue
v = {
"N": lambda x: (v[0],v[1]+x,v[2]),
"S": lambda x: (v[0],v[1]-x,v[2]),
"E": lambda x: (v[0]+x,v[1],v[2]),
"W": lambda x: (v[0]-x,v[1],v[2]),
"R": lambda x: (v[0],v[1],v[2]+x),
"L": lambda x: (v[0],v[1],v[2]-x),
}[d[0]](d[1])
print(abs(v[0])+abs(v[1]))
v = (10,1)
s = (0,0)
for d in i:
if d[0] == "F":
s = (s[0]+v[0]*d[1],s[1]+v[1]*d[1])
continue
v = {
"N": lambda x: (v[0],v[1]+x),
"S": lambda x: (v[0],v[1]-x),
"E": lambda x: (v[0]+x,v[1]),
"W": lambda x: (v[0]-x,v[1]),
"R": lambda x: [(v[0],v[1]), (v[1],-v[0]), (-v[0],-v[1]), (-v[1],v[0])][(x//90)%4],
"L": lambda x: [(v[0],v[1]), (-v[1],v[0]), (-v[0],-v[1]), (v[1],-v[0])][(x//90)%4],
}[d[0]](d[1])
print(abs(s[0])+abs(s[1]))