[py] Port 2015_04
This commit is contained in:
parent
3b7bf7340f
commit
0a6b2fc133
3 changed files with 31 additions and 34 deletions
29
py/aoc/y2015/d04.py
Normal file
29
py/aoc/y2015/d04.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import hashlib
|
||||
|
||||
# PART 1
|
||||
|
||||
|
||||
def leading_zeroes(amount, start):
|
||||
n = 1
|
||||
what = "0" * amount
|
||||
while True:
|
||||
text = (start + str(n)).encode("utf-8")
|
||||
h = hashlib.md5(text).hexdigest()
|
||||
if h[:amount] == what:
|
||||
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}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue