Solve 2015 day 6 and 7.

This commit is contained in:
2024-01-29 21:48:01 -05:00
parent d32bd4c04b
commit 4f9ffa7257
3 changed files with 126 additions and 0 deletions

33
2015/d6.py Normal file
View File

@@ -0,0 +1,33 @@
from lib import *
data = open(0).read()
part_2 = True
lights = [[0 for _ in range(1000)] for _ in range(1000)]
for line in data.splitlines():
x1, y1, x2, y2 = str_to_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)
else:
lights[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
res = 0
for row in lights:
res += sum(row)
print(res)