-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06.py
More file actions
66 lines (53 loc) · 1.51 KB
/
06.py
File metadata and controls
66 lines (53 loc) · 1.51 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
data = open('06.input').readlines()
lights = np.zeros((1000,1000))
for i, line in enumerate(data):
#print("%d %s" % (i, line))
t = line.strip().split(' ')
if 'toggle' in line:
src = t[1]
des = t[3]
else:
src = t[2]
des = t[4]
on_off = 1 if t[1] == 'on' else 0
x1,y1 = [int(x) for x in src.split(',')]
x2,y2 = [int(x) for x in des.split(',')]
for x in range(x1,x2+1):
for y in range(y1,y2+1):
if 'toggle' in line:
lights[x][y] = 1 if lights[x][y] == 0 else 0
else:
lights[x][y] = on_off
count = 0
for a in range(1000):
for b in range(1000):
if lights[a][b] == 1:
count += 1
print("Part 1: %d" % count)
# Part 2
lights = np.zeros((1000,1000))
for i, line in enumerate(data):
#print("%d %s" % (i, line))
t = line.strip().split(' ')
if 'toggle' in line:
src = t[1]
des = t[3]
else:
src = t[2]
des = t[4]
on_off = 1 if t[1] == 'on' else -1
x1,y1 = [int(x) for x in src.split(',')]
x2,y2 = [int(x) for x in des.split(',')]
for x in range(x1,x2+1):
for y in range(y1,y2+1):
if 'toggle' in line:
lights[x][y] += 2
else:
lights[x][y] += on_off
lights[x][y] = 0 if lights[x][y] < 0 else lights[x][y]
count = 0
for a in range(1000):
for b in range(1000):
count += lights[a][b]
print("Part 2: %d" % count)