This commit is contained in:
Stefan Harmuth 2024-12-30 12:25:49 +01:00
parent 6e40549618
commit 070acc8433
3 changed files with 38 additions and 1 deletions

36
day16.py Normal file
View File

@ -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)

1
inputs/input16 Normal file
View File

@ -0,0 +1 @@
01111001100111011

View File

@ -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'
}