days 4, 5 and 6, not bad
This commit is contained in:
18
d06/part1.py
Normal file
18
d06/part1.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
|
||||
M = [[False for _ in range(1000)] for _ in range(1000)]
|
||||
|
||||
for l in sys.stdin.readlines():
|
||||
I = l[:-1].split(' ')
|
||||
xf,yf = list(map(int,I[-3].split(',')))
|
||||
xt,yt = list(map(int,I[-1].split(',')))
|
||||
for x in range(xf,xt+1):
|
||||
for y in range(yf,yt+1):
|
||||
if I[-4] == 'on':
|
||||
M[x][y] = True
|
||||
elif I[-4] == 'off':
|
||||
M[x][y] = False
|
||||
else:
|
||||
M[x][y] = not M[x][y]
|
||||
|
||||
print(sum(x for C in M for x in C))
|
18
d06/part2.py
Normal file
18
d06/part2.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import sys
|
||||
|
||||
M = [[0 for _ in range(1000)] for _ in range(1000)]
|
||||
|
||||
for l in sys.stdin.readlines():
|
||||
I = l[:-1].split(' ')
|
||||
xf,yf = list(map(int,I[-3].split(',')))
|
||||
xt,yt = list(map(int,I[-1].split(',')))
|
||||
for x in range(xf,xt+1):
|
||||
for y in range(yf,yt+1):
|
||||
if I[-4] == 'on':
|
||||
M[x][y] += 1
|
||||
elif I[-4] == 'off':
|
||||
M[x][y] = max(0, M[x][y]-1)
|
||||
else:
|
||||
M[x][y] += 2
|
||||
|
||||
print(sum(x for C in M for x in C))
|
Reference in New Issue
Block a user