day5
This commit is contained in:
parent
07e060f254
commit
4bc1c294b1
45
day05.py
Normal file
45
day05.py
Normal file
@ -0,0 +1,45 @@
|
||||
import hashlib
|
||||
|
||||
from tools.aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
inputs = [
|
||||
[
|
||||
("18f47a30", "input5_test"),
|
||||
("2414bc77", "input5"),
|
||||
],
|
||||
[
|
||||
("437e60fc", "input5"),
|
||||
],
|
||||
]
|
||||
|
||||
def part1(self) -> Any:
|
||||
index = 0
|
||||
password = ""
|
||||
while len(password) < 8:
|
||||
md5sum = hashlib.md5((self.getInput() + str(index)).encode("utf8")).hexdigest()
|
||||
index += 1
|
||||
if md5sum[:5] == "00000":
|
||||
password += md5sum[5]
|
||||
return password
|
||||
|
||||
def part2(self) -> Any:
|
||||
password = [None, None, None, None, None, None, None, None]
|
||||
index = 0
|
||||
while None in password:
|
||||
md5sum = hashlib.md5((self.getInput() + str(index)).encode("utf8")).hexdigest()
|
||||
index += 1
|
||||
if md5sum[:5] == "00000":
|
||||
if md5sum[5] in "01234567":
|
||||
p_index = int(md5sum[5])
|
||||
if password[p_index] is None:
|
||||
password[p_index] = md5sum[6]
|
||||
|
||||
return "".join(password)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
day = Day(2016, 5)
|
||||
day.run(verbose=True)
|
||||
1
inputs/input5
Normal file
1
inputs/input5
Normal file
@ -0,0 +1 @@
|
||||
wtnhxymk
|
||||
1
inputs/input5_test
Normal file
1
inputs/input5_test
Normal file
@ -0,0 +1 @@
|
||||
abc
|
||||
Loading…
Reference in New Issue
Block a user