r/adventofcode • • Dec 05 '16

SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---

--- Day 5: How About a Nice Game of Chess? ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


STAYING ON TARGET IS MANDATORY [?]

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

14 Upvotes

188 comments sorted by

View all comments

Show parent comment

3

u/[deleted] Dec 05 '16

Hehe, I kind of did the same as you:

import md5
import sys

door_id = "ffykfhsq"
#door_id = "abc"
running_num = 0
passbuild = {}
password = ['-', '-', '-', '-', '-', '-', '-', '-' ]

while len(passbuild) < 8:
    test = door_id + str(running_num)
    hashed = md5.new(test).hexdigest()
    if running_num % 1000 == 0:
        sys.stdout.write("password: {} cracking hash: {} \r".format("".join(password),hashed))
        sys.stdout.flush()
    if hashed.startswith("00000"):
        place = hashed[5]
        char = hashed[6]
        if place.isdigit() and int(place) > -1 and int(place) < 8:
            if int(place) not in passbuild:
                passbuild[int(place)] = char
                password[int(place)] = char
    running_num += 1

sys.stdout.write("password: {} \r".format("".join(password)))
sys.stdout.flush()
print("password: {} \r".format("".join(password)))

Looks really fancy in the console :D