Update 2015 solutions

This commit is contained in:
2024-10-20 15:19:25 -04:00
parent 87ab42743e
commit e73fa3bae7
16 changed files with 362 additions and 411 deletions

View File

@@ -1,33 +1,29 @@
from lib import *
from lib import get_data, ints
from collections import defaultdict as DD
data = open(0).read()
part_2 = True
lights = [[0 for _ in range(1000)] for _ in range(1000)]
data = get_data(__file__)
ons = set()
ons2 = DD(int)
for line in data.splitlines():
x1, y1, x2, y2 = str_to_ints(line)
x1, y1, x2, y2 = ints(line)
for x in range(x1, x2 + 1):
for y in range(y1, y2 + 1):
if part_2:
if "on" in line:
lights[x][y] += 1
elif "off" in line:
lights[x][y] = max(0, lights[x][y] - 1)
if "off" in line:
if (x, y) in ons:
ons.remove((x, y))
ons2[(x, y)] = max(ons2[(x, y)] - 1, 0)
elif "on" in line:
ons.add((x, y))
ons2[(x, y)] += 1
elif "toggle" in line:
if (x, y) in ons:
ons.remove((x, y))
else:
lights[x][y] += 2
ons.add((x, y))
ons2[(x, y)] += 2
else:
if "on" in line:
lights[x][y] = 1
elif "off" in line:
lights[x][y] = 0
else:
if lights[x][y] == 1:
lights[x][y] = 0
else:
lights[x][y] = 1
assert False
res = 0
for row in lights:
res += sum(row)
print(res)
print(len(ons))
print(sum(ons2.values()))