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.

14 Upvotes

272 comments sorted by

View all comments

Show parent comment

2

u/rustynailz Dec 04 '15

You can use the copy() and update() functions from the md5() object:

def find_hash_key (t,n):
    m = md5(t)
    for i in range(10000000):
        m2 = m.copy()
        m2.update(str(i))
        if m2.hexdigest()[:n] == '0'*n:
            return i