Guest User

Reibello AoC 14

a guest
Dec 14th, 2016
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. #aoc_2015_14.py
  2. import hashlib
  3. import itertools
  4.  
  5. salt =  "yjdafjpo"
  6. pad = []
  7.  
  8. def make_hash(s,i):
  9.     '''
  10. '''
  11.     text = s + str(i)
  12.     hashkey = hashlib.md5(text.encode('utf-8')).hexdigest()
  13.     return hashkey
  14.  
  15. def extend_hash(h):
  16.     '''
  17. '''
  18.     for x in range(2016):
  19.         h = hashlib.md5(h.encode('utf-8')).hexdigest()
  20.     return h
  21.  
  22. previous_hashes = {}
  23.  
  24. while len(pad) < 5:
  25.     for x in itertools.count(0):
  26.         test_key = extend_hash(make_hash(salt, x))
  27.         for i in range(len(test_key)-2):
  28.             if test_key[i] == test_key[i+1] and test_key[i] == test_key[i+2]:
  29.                 char = test_key[i]
  30.                 break
  31.         else:
  32.             continue
  33.         for y in range(x+1, x+1001):
  34.             if y in previous_hashes:
  35.                 quintcheck = previous_hashes[y]
  36.             else:
  37.                 quintcheck = extend_hash(make_hash(salt, y))
  38.                 previous_hashes[y] = quintcheck
  39.             if char not in quintcheck:
  40.                 continue
  41.             else:
  42.                 for j in range(len(quintcheck)-4):
  43.                     if quintcheck[j] == quintcheck[j+1] and quintcheck[j] == quintcheck[j+2] and quintcheck[j] == quintcheck[j+3] and quintcheck[j] == quintcheck[j+4] and quintcheck[j] == char:
  44.                         pad.append(x)
  45.                         print(x, test_key)
  46.                         print(y, quintcheck)
  47.                         print()
  48.                         break
Advertisement
Add Comment
Please, Sign In to add comment