diff --git a/day05.py b/day05.py new file mode 100644 index 0000000..461eb37 --- /dev/null +++ b/day05.py @@ -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) diff --git a/inputs/input5 b/inputs/input5 new file mode 100644 index 0000000..d152446 --- /dev/null +++ b/inputs/input5 @@ -0,0 +1 @@ +wtnhxymk \ No newline at end of file diff --git a/inputs/input5_test b/inputs/input5_test new file mode 100644 index 0000000..f2ba8f8 --- /dev/null +++ b/inputs/input5_test @@ -0,0 +1 @@ +abc \ No newline at end of file