Solve 2015 days 8-10.

This commit is contained in:
2024-01-30 19:29:31 -05:00
parent 4f9ffa7257
commit 0dfb4f974a
4 changed files with 107 additions and 1 deletions

35
2015/d10.py Normal file
View File

@@ -0,0 +1,35 @@
from functools import lru_cache
data = open(0).read().strip()
part_1 = False
if part_1:
repeats = 40
else:
repeats = 50
@lru_cache
def look_and_say(data: str) -> str:
r = ""
i = 0
while i < len(data):
count = 0
c = data[i]
while i < len(data) and data[i] == c:
count += 1
i += 1
r += f"{count}{c}"
return r
CHUNK_SIZE = 10000
for _ in range(repeats):
ndata = ""
lo, up = 0, CHUNK_SIZE
while up < len(data):
while up < len(data) and data[up - 1] == data[up]:
up += 1
ndata += look_and_say(data[lo:up])
lo, up = up, up + CHUNK_SIZE
ndata += look_and_say(data[lo:up])
data = ndata
print(len(data))