#Skip to menu

Day 4, Year 2015: The Ideal Stocking Stuffer

First read the problem description.
import hashlib

def mine(key, zeros=5):
    key = key.encode()
    n = 0
    z = '0' * zeros
    while True:
        n += 1
        nb = str(n).encode()
        hex = hashlib.md5(key + nb).hexdigest()
        if hex.startswith(z):
            return n
assert mine('abcdef', 5) == 609043
assert mine('pqrstuv', 5) == 1048970
mine('yzbqklnj', 5)
282749
mine('yzbqklnj', 6)
9962624

Source code of the solution(s):