Solve 2016 day 17.
This commit is contained in:
40
2016/d17.py
Normal file
40
2016/d17.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import hashlib
|
||||
from collections import deque
|
||||
from lib import add2
|
||||
|
||||
|
||||
def solve():
|
||||
part_1 = False
|
||||
DIRS = [("U", (-1, 0)), ("D", (1, 0)), ("L", (0, -1)), ("R", (0, 1))]
|
||||
with open("i17.txt") as f:
|
||||
passcode = f.read().strip()
|
||||
|
||||
maxlen = 0
|
||||
poss = deque([((0, 0), f"{passcode}")])
|
||||
while poss:
|
||||
if part_1:
|
||||
pos, path = poss.popleft()
|
||||
else:
|
||||
pos, path = poss.pop()
|
||||
|
||||
if pos == (3, 3):
|
||||
if part_1:
|
||||
print(path[len(passcode):])
|
||||
return
|
||||
else:
|
||||
l = len(path) - len(passcode)
|
||||
if l > maxlen:
|
||||
maxlen = l
|
||||
else:
|
||||
status = hashlib.md5(f"{path}".encode()).hexdigest()
|
||||
for (c, d), s in zip(DIRS, status[:4]):
|
||||
if s in "bcdef":
|
||||
npos = add2(pos, d)
|
||||
npath = path + c
|
||||
if npos[0] >= 0 and npos[0] < 4 and npos[1] >= 0 and npos[1] < 4:
|
||||
poss.append((npos, npath))
|
||||
print(maxlen)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solve()
|
||||
@@ -47,7 +47,10 @@ written in Python.
|
||||
- Day 12: 10:05 okay
|
||||
- Day 13: 9:43 okayish
|
||||
- Day 14: 120:00 struggled with this one (example incorrect?)
|
||||
- Day 15:
|
||||
- Day 15: Trial and error. Should use CRT instead.
|
||||
- Day 16: 14:11
|
||||
- Day 17: 45:00 didn't follow instructions... focus!
|
||||
- Day 18:
|
||||
|
||||
# 2017
|
||||
|
||||
|
||||
Reference in New Issue
Block a user