Advent of Code 2016 solutions https://adventofcode.com/2016/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

05.py 635B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python3
  2. import hashlib
  3. import itertools
  4. from multiprocessing import Pool
  5. door = 'abbhdwsy'
  6. def hash(x):
  7. return hashlib.md5((door + str(x)).encode('utf-8')).hexdigest()
  8. pool = Pool()
  9. hashes = pool.imap(hash, itertools.count(), 10000)
  10. zeroes = (h for h in hashes if h.startswith('00000'))
  11. part1 = ''
  12. part2 = ['_'] * 8
  13. for h in zeroes:
  14. if len(part1) < 8:
  15. part1 += h[5]
  16. if h[5].isdigit() and int(h[5]) < len(part2) and part2[int(h[5])] == '_':
  17. part2[int(h[5])] = h[6]
  18. if '_' not in part2:
  19. print("Part one: %s" % part1)
  20. print("Part two: %s" % ''.join(part2))
  21. break