Skip to content

Commit

Permalink
WIP 2016 d01
Browse files Browse the repository at this point in the history
  • Loading branch information
KristobalJunta committed Dec 3, 2020
1 parent 6a0b022 commit b7f26ea
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
52 changes: 52 additions & 0 deletions 2016/d01/d01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import math


def get_input():
with open('test.txt') as f:
data = f.read()

data = data.strip().split(',')
data = [s.strip() for s in data]
return data


def vec_add(v1, v2):
x1, y1 = v1
x2, y2 = v2
return [x1 + x2, y1 + y2]


def manh_dist(v1, v2):
x1, y1 = v1
x2, y2 = v2
return abs(x1 - x2) +abs(y1 - y2)


def part1(data):
cur_pos = [0, 0]
cur_face = 0
dirs = [
[0, 1],
[1, 0],
[0, -1],
[-1, 0],
]

for item in data:
d, step = item[0], int(item[1:])
if d == 'L':
cur_face = (cur_face - 1) % 4
else:
cur_face = (cur_face + 1) % 4

idx = (cur_face + 1) % 2
new_vec = dirs[cur_face]
new_vec[idx] = new_vec[idx] * step
cur_pos = vec_add(cur_pos, new_vec)

print(cur_pos)
print(manh_dist([0, 0], cur_pos))


data = get_input()
part1(data)
1 change: 1 addition & 0 deletions 2016/d01/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L4, L1, R4, R1, R1, L3, R5, L5, L2, L3, R2, R1, L4, R5, R4, L2, R1, R3, L5, R1, L3, L2, R5, L4, L5, R1, R2, L1, R5, L3, R2, R2, L1, R5, R2, L1, L1, R2, L1, R1, L2, L2, R4, R3, R2, L3, L188, L3, R2, R54, R1, R1, L2, L4, L3, L2, R3, L1, L1, R3, R5, L1, R5, L1, L1, R2, R4, R4, L5, L4, L1, R2, R4, R5, L2, L3, R5, L5, R1, R5, L2, R4, L2, L1, R4, R3, R4, L4, R3, L4, R78, R2, L3, R188, R2, R3, L2, R2, R3, R1, R5, R1, L1, L1, R4, R2, R1, R5, L1, R4, L4, R2, R5, L2, L5, R4, L3, L2, R1, R1, L5, L4, R1, L5, L1, L5, L1, L4, L3, L5, R4, R5, R2, L5, R5, R5, R4, R2, L1, L2, R3, R5, R5, R5, L2, L1, R4, R3, R1, L4, L2, L3, R2, L3, L5, L2, L2, L1, L2, R5, L2, L2, L3, L1, R1, L4, R2, L4, R3, R5, R3, R4, R1, R5, L3, L5, L5, L3, L2, L1, R3, L4, R3, R2, L1, R3, R1, L2, R4, L3, L3, L3, L1, L2
1 change: 1 addition & 0 deletions 2016/d01/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
R2, R2, R2

0 comments on commit b7f26ea

Please sign in to comment.