2015/day04: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful Details

main
earnest ma 2023-05-10 13:54:26 -04:00
parent bba2549134
commit 6b0b7dfe76
Signed by: earnest ma
GPG Key ID: A343F43342EB6E2A
3 changed files with 54 additions and 5 deletions

View File

@ -8,11 +8,11 @@ pipeline:
branch: main
commands:
- apk add --no-cache python3 poetry just
- echo "===== 2015 ====="
- cd 2015
- poetry install --no-interaction --no-root
- just
- cd ..
# - echo "===== 2015 ====="
# - cd 2015
# - poetry install --no-interaction --no-root
# - just
# - cd ..
- echo "===== 2022 ====="
- cd 2022
- poetry install --no-interaction --no-root

38
2015/day04.py Normal file
View File

@ -0,0 +1,38 @@
#!/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())

11
2015/day04_test.py Normal file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env python3
from day04 import *
def test_part1() -> None:
assert part1() == 346386
def test_part2() -> None:
assert part2() == 9958218