62 lines
2 KiB
Python
62 lines
2 KiB
Python
with open("./input", "r") as file:
|
|
toPrase = list(file.read().split("\n"))
|
|
|
|
pol = 0
|
|
leds = []
|
|
|
|
for i in range(999 * 999):
|
|
leds.append(0)
|
|
|
|
crt = 1
|
|
|
|
for command in toPrase:
|
|
if command != "":
|
|
cmdType = 0 #0 = turn on // 1 = turn off // 2 = toggle
|
|
"""turn on x1,y1 through x2,y2"""
|
|
if command.startswith("turn on"):
|
|
cmdType = 0
|
|
crtcmd = command.replace("turn on ", "")
|
|
start = crtcmd.split(" through ")[0]
|
|
end = crtcmd.split(" through ")[1].replace(" through ", "")
|
|
x1 = int(start.split(",")[0])
|
|
y1 = int(start.split(",")[1])
|
|
x2 = int(end.split(",")[0])
|
|
y2 = int(end.split(",")[1])
|
|
if command.startswith("turn off"):
|
|
cmdType = 1
|
|
crtcmd = command.replace("turn off ", "")
|
|
start = crtcmd.split(" through ")[0]
|
|
end = crtcmd.split(" through ")[1].replace(" through ", "")
|
|
x1 = int(start.split(",")[0])
|
|
y1 = int(start.split(",")[1])
|
|
x2 = int(end.split(",")[0])
|
|
y2 = int(end.split(",")[1])
|
|
if command.startswith("toggle"):
|
|
cmdType = 2
|
|
crtcmd = command.replace("toggle ", "")
|
|
start = crtcmd.split(" through ")[0]
|
|
end = crtcmd.split(" through ")[1].replace(" through ", "")
|
|
x1 = int(start.split(",")[0])
|
|
y1 = int(start.split(",")[1])
|
|
x2 = int(end.split(",")[0])
|
|
y2 = int(end.split(",")[1])
|
|
for x in range(x1-1, x2):
|
|
for y in range(y1-1, y2):
|
|
index = 1000 * x + y+1
|
|
if cmdType == 0:
|
|
leds[index] += 1
|
|
if cmdType == 1:
|
|
if leds[index] <= 1:
|
|
leds[index] = 0
|
|
else:
|
|
leds[index] -= 1
|
|
if cmdType == 2:
|
|
leds[index] += 2
|
|
print(f"succesfully parsed command \"{command}\" ({crt}/{len(toPrase)})")
|
|
crt += 1
|
|
|
|
|
|
for led in leds:
|
|
pol += led
|
|
|
|
print(pol)
|