Skip to content

Instantly share code, notes, and snippets.

@lyxal

lyxal/frick.py Secret

Created December 12, 2020 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyxal/7d1a353f0ff029ed32a1ae92452ad045 to your computer and use it in GitHub Desktop.
Save lyxal/7d1a353f0ff029ed32a1ae92452ad045 to your computer and use it in GitHub Desktop.
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