advent/2015/6/sol2.py
2022-11-06 13:55:53 -06:00

47 lines
1.1 KiB
Python

file = [i.rstrip() for i in open("input").readlines()]
# create the light array
lights = [[0 for i in range(1000)] for j in range(1000)]
for i in file:
offset = False
splitted = i.split(" ")
command = splitted[0]
if splitted[1] in ["on", "off"]:
command += splitted[1]
offset = True
if offset:
c1 = splitted[2].split(',')
else:
c1 = splitted[1].split(',')
if offset:
c2 = splitted[4].split(',')
else:
c2 = splitted[3].split(',')
print(c1, c2)
x = int(c1[0])
xc = int(c2[0])
y = int(c1[1])
yc = int(c2[1])
print(command)
for j in range(xc - x + 1):
for k in range(yc - y + 1):
pos = (x + j, y + k)
if command == "turnon":
lights[x + j][y + k] += 1
if command == "turnoff":
if not lights[x + j][y + k] == 0:
lights[x + j][y + k] -= 1
if command == "toggle":
lights[x + j][y + k] += 2
c = 0
for i in lights:
for j in i:
c += j
print(c)