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)