Created
December 12, 2020 07:20
-
-
Save rendyanthony/1999f4d41e178e4d1a7fbd1c49cf96e4 to your computer and use it in GitHub Desktop.
Advent of Code Day 12 (Part 1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COMPASS = { | |
"E": (+1, 0), | |
"S": (0, +1), | |
"W": (-1, 0), | |
"N": (0, -1) | |
} | |
ship_pos = [0, 0] | |
ship_heading = 0 | |
nav_list = [(n[0], int(n[1:])) for n in open("input_12")] | |
for nav, value in nav_list: | |
if nav in ("R", "L"): | |
if nav == "L": | |
value = -value | |
ship_heading = (ship_heading+value)%360 | |
if nav == "F": | |
nav = "ESNW"[ship_heading//90] | |
if nav in COMPASS.keys(): | |
ship_pos[0] += COMPASS[nav][0] * value | |
ship_pos[1] += COMPASS[nav][1] * value | |
print(abs(ship_pos[0]) + abs(ship_pos[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment