39 lines
599 B
Python
39 lines
599 B
Python
#!/usr/bin/env python3
|
|
|
|
import hashlib
|
|
|
|
|
|
f = open("day04.txt", "r")
|
|
pin = f.read().strip()
|
|
|
|
|
|
def part1() -> int:
|
|
num = 1
|
|
|
|
while True:
|
|
res = hashlib.md5(f"{pin}{num}".encode("UTF-8")).hexdigest()
|
|
# print(num, res)
|
|
|
|
if res[0:5] == "00000":
|
|
return num
|
|
|
|
num += 1
|
|
|
|
|
|
def part2() -> int:
|
|
num = 1
|
|
|
|
while True:
|
|
res = hashlib.md5(f"{pin}{num}".encode("UTF-8")).hexdigest()
|
|
# print(num, res)
|
|
|
|
if res[0:6] == "000000":
|
|
return num
|
|
|
|
num += 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(part1())
|
|
print(part2())
|