diff --git a/day16.py b/day16.py new file mode 100644 index 0000000..40e93c3 --- /dev/null +++ b/day16.py @@ -0,0 +1,36 @@ +from tools.aoc import AOCDay +from typing import Any + +class Day(AOCDay): + inputs = [ + [ + ("11111000111110000", "input16"), + ], + [ + ("10111100110110100", "input16"), + ] + ] + + def get_checksum(self, disk_size: int) -> str: + state = self.getInput() + while len(state) < disk_size: + state = state + "0" + "".join("1" if x == "0" else "0" for x in reversed(state)) + + state = state[:disk_size] + while len(state) % 2 == 0: + state = "".join("1" if state[i] == state[i + 1] else "0" for i in range(0, len(state) - 1, 2)) + + return state + + def part1(self) -> Any: + disk_size = 272 + return self.get_checksum(disk_size) + + def part2(self) -> Any: + disk_size = 35651584 + return self.get_checksum(disk_size) + + +if __name__ == '__main__': + day = Day(2016, 16) + day.run(verbose=True) diff --git a/inputs/input16 b/inputs/input16 new file mode 100644 index 0000000..dd44179 --- /dev/null +++ b/inputs/input16 @@ -0,0 +1 @@ +01111001100111011 diff --git a/start_day.py b/start_day.py index 1cc1de2..6cce497 100755 --- a/start_day.py +++ b/start_day.py @@ -11,7 +11,7 @@ import webbrowser YEAR = 2016 CHARMS = { - 'Linux': '~/.local/share/JetBrains/Toolbox/scripts/pycharm', + 'Linux': '/home/pennywise/.local/share/JetBrains/Toolbox/scripts/pycharm', 'Windows': r'C:\Users\pennywise\AppData\Local\JetBrains\Toolbox\scripts\pycharm.cmd' }