advent-of-code/py/aoc/y2015/d04.py
2022-12-06 21:25:40 +01:00

17 lines
381 B
Python

import hashlib
def brute_force(seed, start):
n = 1
while True:
text = f"{seed}{n}".encode("utf-8")
h = hashlib.md5(text).hexdigest()
if h.startswith(start):
return n
n += 1
def solve(inputstr):
seed = inputstr.strip()
print(f"Part 1: {brute_force(seed, '00000')}")
print(f"Part 2: {brute_force(seed, '000000')}")