Skip to content

Commit 9b30f8a

Browse files
committed
2016 D1
1 parent d171d66 commit 9b30f8a

26 files changed

+28
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

2016/data/day1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
L5, R1, L5, L1, R5, R1, R1, L4, L1, L3, R2, R4, L4, L1, L1, R2, R4, R3, L1, R4, L4, L5, L4, R4, L5, R1, R5, L2, R1, R3, L2, L4, L4, R1, L192, R5, R1, R4, L5, L4, R5, L1, L1, R48, R5, R5, L2, R4, R4, R1, R3, L1, L4, L5, R1, L4, L2, L5, R5, L2, R74, R4, L1, R188, R5, L4, L2, R5, R2, L4, R4, R3, R3, R2, R1, L3, L2, L5, L5, L2, L1, R1, R5, R4, L3, R5, L1, L3, R4, L1, L3, L2, R1, R3, R2, R5, L3, L1, L1, R5, L4, L5, R5, R2, L5, R2, L1, L5, L3, L5, L5, L1, R1, L4, L3, L1, R2, R5, L1, L3, R4, R5, L4, L1, R5, L1, R5, R5, R5, R2, R1, R2, L5, L5, L5, R4, L5, L4, L4, R5, L2, R1, R5, L1, L5, R4, L3, R4, L2, R3, R3, R3, L2, L2, L2, L1, L4, R3, L4, L2, R2, R5, L1, R2

2016/data/day1_1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
R5, L5, R5, R3

2016/day_1.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re, math, numpy as np
2+
3+
finder = re.compile(r'([LR]{1}\d+)(?:,)?')
4+
5+
with open('data/day1.txt') as fp:
6+
movements = finder.findall(fp.read())
7+
8+
looking = 0
9+
pos = (0, 0)
10+
dual = None
11+
m_tbl = [[0,1],[1,0],[0,-1],[-1,0]]
12+
visited = []
13+
14+
for m in movements:
15+
looking = (looking + (1 if m[:1] == 'R' else -1)) % 4
16+
17+
for i in range(1, int(m[1:]) + 1):
18+
pos = (pos[0] + m_tbl[looking][0], pos[1] + m_tbl[looking][1])
19+
20+
if dual == None and pos in visited:
21+
dual = pos
22+
visited += [pos]
23+
24+
25+
print("Ans 1:", abs(pos[0]) + abs(pos[1]))
26+
print("Ans 2:", abs(dual[0]) + abs(dual[1]))

0 commit comments

Comments
 (0)