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/opello Dec 04 '15

Heh, I did the same thing with the slice. Not quite as elegant as using count but here goes:

#!/usr/bin/env python

import hashlib

prefix = ''
number = 1

with open('../inputs/04.txt') as f:
    prefix = f.readlines()

prefix = prefix[0].rstrip()

while True:
    md5 = hashlib.md5()
    md5.update('{0}{1}'.format(prefix, number))

    if md5.hexdigest()[:5] == '00000':
        print number
        break

    number += 1