diff --git a/py/aoc/y2015/d04.py b/py/aoc/y2015/d04.py index 2a5a769..541d17b 100644 --- a/py/aoc/y2015/d04.py +++ b/py/aoc/y2015/d04.py @@ -1,29 +1,17 @@ import hashlib -# PART 1 - -def leading_zeroes(amount, start): +def brute_force(seed, start): n = 1 - what = "0" * amount while True: - text = (start + str(n)).encode("utf-8") + text = f"{seed}{n}".encode("utf-8") h = hashlib.md5(text).hexdigest() - if h[:amount] == what: + if h.startswith(start): return n - - # if n % 100000 == 0: - # print(f"{n:9} {text} {h}") - n += 1 -# PART 2 - - def solve(inputstr): - hashstart = inputstr.strip() - n = leading_zeroes(5, hashstart) - print(f"Part 1: {n}") - n_2 = leading_zeroes(6, hashstart) - print(f"Part 2: {n_2}") + seed = inputstr.strip() + print(f"Part 1: {brute_force(seed, '00000')}") + print(f"Part 2: {brute_force(seed, '000000')}")