day9
This commit is contained in:
parent
e0b0149449
commit
345e4830bc
52
day09.py
Normal file
52
day09.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
from tools.aoc import AOCDay
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
def get_decompressed_len(zipped: str, p2: bool = False) -> int:
|
||||||
|
length = 0
|
||||||
|
x = 0
|
||||||
|
while x < len(zipped):
|
||||||
|
if zipped[x] != "(":
|
||||||
|
length += 1
|
||||||
|
x += 1
|
||||||
|
continue
|
||||||
|
|
||||||
|
x += 1
|
||||||
|
marker = ""
|
||||||
|
while zipped[x] != ")":
|
||||||
|
marker += zipped[x]
|
||||||
|
x += 1
|
||||||
|
|
||||||
|
x += 1
|
||||||
|
c_count, repeats = map(int, marker.split("x"))
|
||||||
|
if not p2:
|
||||||
|
length += c_count * repeats
|
||||||
|
else:
|
||||||
|
repeator = zipped[x : x + c_count]
|
||||||
|
length += repeats * get_decompressed_len(repeator, p2=True)
|
||||||
|
|
||||||
|
x += c_count
|
||||||
|
|
||||||
|
return length
|
||||||
|
|
||||||
|
|
||||||
|
class Day(AOCDay):
|
||||||
|
inputs = [
|
||||||
|
[
|
||||||
|
(183269, "input9"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
(11317278863, "input9"),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
|
||||||
|
def part1(self) -> Any:
|
||||||
|
return get_decompressed_len(self.getInput())
|
||||||
|
|
||||||
|
def part2(self) -> Any:
|
||||||
|
return get_decompressed_len(self.getInput(), True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
day = Day(2016, 9)
|
||||||
|
day.run(verbose=True)
|
||||||
1
inputs/input9
Normal file
1
inputs/input9
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user