34 lines
894 B
Python
34 lines
894 B
Python
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)
|