day16
This commit is contained in:
parent
6e40549618
commit
070acc8433
36
day16.py
Normal file
36
day16.py
Normal 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
1
inputs/input16
Normal file
@ -0,0 +1 @@
|
||||
01111001100111011
|
||||
@ -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'
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user