# Day 17 - Advent of Code 2016

Working solution for the day 17 puzzles.

### Parts One and Two

``````""" day_17_01_02.py """

# usage: python3 day_17_01_02.py udskfozm

import sys
from hashlib import md5

def status(secret, salt):
""" what's the door status """
digest = md5()
digest.update((secret + salt).encode())
return [i not in 'bcdef' for i in digest.hexdigest()[:4]]

def move(pos, goal, secret, steps=''):
""" move to goal """
global solution

if pos == goal:
return pos, steps

deltas = [(-1, 0), (1, 0), (0, -1), (0, 1)]
symbols = ['U', 'D', 'L', 'R']

for i, locked in enumerate(status(secret, steps)):
if locked:
continue
row = pos + deltas[i]
col = pos + deltas[i]
if 0 <= row <= 3 and 0 <= col <= 3:
next_pos = row, col
next_steps = steps + symbols[i]
end_pos, end_steps = move(next_pos, goal, secret, next_steps)
if end_pos == goal:
if solution == '' or len(end_steps) < len(solution):
solution = end_steps
if solution == '' or len(end_steps) > len(solution):
solution = end_steps

return pos, steps

passcode = sys.argv
start = 0, 0
end = 3, 3
solution = ['', '']

move(start, end, passcode)
print(solution)
print(len(solution))
``````