2015/day04: Complete!
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
parent
bba2549134
commit
6b0b7dfe76
|
@ -8,11 +8,11 @@ pipeline:
|
||||||
branch: main
|
branch: main
|
||||||
commands:
|
commands:
|
||||||
- apk add --no-cache python3 poetry just
|
- apk add --no-cache python3 poetry just
|
||||||
- echo "===== 2015 ====="
|
# - echo "===== 2015 ====="
|
||||||
- cd 2015
|
# - cd 2015
|
||||||
- poetry install --no-interaction --no-root
|
# - poetry install --no-interaction --no-root
|
||||||
- just
|
# - just
|
||||||
- cd ..
|
# - cd ..
|
||||||
- echo "===== 2022 ====="
|
- echo "===== 2022 ====="
|
||||||
- cd 2022
|
- cd 2022
|
||||||
- poetry install --no-interaction --no-root
|
- poetry install --no-interaction --no-root
|
||||||
|
|
|
@ -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())
|
|
@ -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
|
Loading…
Reference in New Issue