r/adventofcode • • Dec 04 '15

SOLUTION MEGATHREAD --- Day 4 Solutions ---

--- Day 4: The Ideal Stocking Stuffer ---

Post your solution as a comment. Structure your post like the Day Three thread.

16 Upvotes

272 comments sorted by

View all comments

Show parent comment

1

u/Filostrato Dec 04 '15 edited Dec 04 '15

My solution does exactly the same, and finds what appears to me to be the right answer, but this answer is somehow rejected by the site.

EDIT: It's just me being stupid, so never mind. I was trying to input the entire key as the solution, instead of just the added number. This is a working solution.

This is the code:

from hashlib import md5

def computeMD5hash(string):
    return = md5(string.encode()).hexdigest()

secret = "yzbqklnj"

for n in range(1, 1000000):
    key = secret + str(n)
    h = computeMD5hash(key)
    if h[:5] == "00000":
        print(key, h)
        break