47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
file = [i.rstrip() for i in open("input").readlines()]
|
|
# create the light array
|
|
lights = [[False 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] = True
|
|
if command == "turnoff":
|
|
lights[x + j][y + k] = False
|
|
if command == "toggle":
|
|
lights[x + j][y + k] = not lights[x + j][y + k]
|
|
|
|
c = 0
|
|
for i in lights:
|
|
for j in i:
|
|
if j:
|
|
c += 1
|
|
|
|
print(c)
|