You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
984 B
Python
41 lines
984 B
Python
from collections import defaultdict
|
|
|
|
with open("input") as f:
|
|
puzzle_input = [n.strip() for n in f.readlines()]
|
|
|
|
|
|
lights = [[0 for _ in range(1000)] for _ in range(1000)]
|
|
|
|
for instruction in puzzle_input:
|
|
from_coords = instruction.split(" ")[-1::-1][2]
|
|
to_coords = instruction.split(" ")[-1::-1][0]
|
|
from_coords = [int(x) for x in from_coords.split(",")]
|
|
to_coords = [int(x) for x in to_coords.split(",")]
|
|
|
|
[x_1, y_1] = from_coords
|
|
[x_2, y_2] = to_coords
|
|
|
|
diff = 0
|
|
if instruction.startswith("turn on"):
|
|
diff = 1
|
|
elif instruction.startswith("turn off"):
|
|
diff = -1
|
|
else:
|
|
diff = 2
|
|
|
|
for x in range(x_1, x_2 + 1):
|
|
for y in range(y_1, y_2 + 1):
|
|
lights[x][y] = lights[x][y] + diff
|
|
if lights[x][y] < 0:
|
|
lights[x][y] = 0
|
|
|
|
print(instruction, from_coords, to_coords)
|
|
|
|
brightness = 0
|
|
|
|
for row in lights:
|
|
for light in row:
|
|
brightness += light
|
|
|
|
print(brightness)
|