Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day12_1():
- with open("input.txt", "r") as file:
- data = file.readlines()
- data = [(i[:1], int(i[1:-1])) for i in data]
- angle_to_drxn = {0: "E", 90: "N", 180: "W", 270: "S"}
- totals = {"N": 0, "S": 0, "E": 0, "W": 0}
- curr_angle = 0
- for drxn, val in data:
- if drxn == "L":
- curr_angle = (curr_angle + val) % 360
- elif drxn == "R":
- curr_angle = (curr_angle - val) % 360
- elif drxn == "F":
- totals[angle_to_drxn[curr_angle]] += val
- else:
- totals[drxn] += val
- return abs(totals["N"] - totals["S"]) + abs(totals["E"] - totals["W"])
Advertisement
Add Comment
Please, Sign In to add comment