-
-
Save lyxal/7d1a353f0ff029ed32a1ae92452ad045 to your computer and use it in GitHub Desktop.
This file contains 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
from itertools import * | |
from string import * | |
from math import * | |
i = open("input.txt").read().split("\n") | |
i = [[l[0], int(l[1:])] for l in i] | |
row = 0 | |
col = 0 | |
out = 0 | |
val = 0 | |
rows = [] | |
prev = [""] | |
dirs = [0, 1, 2, 3] # East North West South | |
eay = 0 | |
way_row, way_col = 10, 1 | |
for direction in i: | |
#print(eay, abs(row), abs(col), way_row, way_col) | |
if direction[0] == "F": | |
for k in range(direction[1]): | |
row += way_row | |
col += way_col | |
elif direction[0] in "NEWS": | |
feay = "ENWS".index(direction[0]) | |
if feay == 0: way_row += direction[1] | |
if feay == 1: way_col += direction[1] | |
if feay == 2: way_row -= direction[1] | |
if feay == 3: way_col -= direction[1] | |
elif direction[0] == "R": | |
times = direction[1] // 90 | |
for n in range(times): | |
temp = way_col | |
way_col = -way_row | |
way_row = temp | |
elif direction[0] == "L": | |
times = direction[1] // 90 | |
for k in range(times): | |
temp = way_col | |
way_col = way_row | |
way_row = -temp | |
print(abs(row) + abs(col)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment