2016-12-05 - How About a Nice Game of Chess?
(original .ipynb)import hashlib puzzle_input_str = "wtnhxymk" def md5(s): return hashlib.md5(s.encode('utf-8')).hexdigest() def part_one(input_str): password = [] n = 0 while len(password) < 8: hashed_door_id = md5(input_str + str(n)) if hashed_door_id[:5] == "00000": password += hashed_door_id[5] n += 1 return "".join(password) assert "18f47a30" == part_one("abc") print("part one:", part_one(puzzle_input_str))
part one: 2414bc77
def part_two(input_str): password = [None] * 8 n = 0 while True: hashed_door_id = md5(input_str + str(n)) if hashed_door_id[:5] == "00000": position = int(hashed_door_id[5], 16) c = hashed_door_id[6] if position < 8 and password[position] is None: password[position] = c if all(password): return "".join(password) n += 1 return "".join(password) assert "05ace8e3" == part_two("abc") print("part_two:", part_two(puzzle_input_str))
part_two: 437e60fc