-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadventcode_day6b.py
More file actions
32 lines (30 loc) · 830 Bytes
/
adventcode_day6b.py
File metadata and controls
32 lines (30 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
instructions = open('day6.txt', 'r').read().split('\n')
lights = []
for i in range(1000):
col = []
for j in range(1000):
col.append(0)
lights.append(col)
for instruction in instructions:
words = instruction.split(' ')
if (words[0]=='turn'):
start = words[2].split(',')
end = words[4].split(',')
flag = True if words[1]=='on' else False
for i in range(int(start[0]),int(end[0])+1):
for j in range(int(start[1]),int(end[1])+1):
if(flag):
lights[i][j] += 1
elif(lights[i][j] != 0):
lights[i][j] -= 1
if (words[0]=='toggle'):
start = words[1].split(',')
end = words[3].split(',')
for i in range(int(start[0]),int(end[0])+1):
for j in range(int(start[1]),int(end[1])+1):
lights[i][j] += 2
total = 0
for col in lights:
for elem in col:
total += elem
print (total)