day 8, compare two approaches for part 1

This commit is contained in:
setop 2022-12-09 00:06:28 +01:00
parent 82b23cf1b4
commit e51de70c36
2 changed files with 27 additions and 2 deletions

View File

@ -1,7 +1,8 @@
import sys import sys
L = list(list(map(int,s)) for s in sys.stdin.read().splitlines()) L = list(list(map(int,s)) for s in sys.stdin.read().splitlines())
W = len(L[0]) ; H = len(L) W = len(L[0]) ; H = len(L)
N=0 N = 0
Q = 0
for i in range(H): for i in range(H):
for j in range(W): for j in range(W):
v = L[i][j] v = L[i][j]
@ -14,4 +15,5 @@ for i in range(H):
# look down # look down
d = all(L[k][j]<v for k in range(i+1,H)) d = all(L[k][j]<v for k in range(i+1,H))
N += (r|l|u|d) N += (r|l|u|d)
print(N, W*H) Q += W + H
print(N, W*H*(W+H), Q)

23
d08/part1b.py Normal file
View File

@ -0,0 +1,23 @@
import sys
L = list(list(map(int,s)) for s in sys.stdin.read().splitlines())
W = len(L[0]) ; H = len(L)
size = W * H
Q = 0
def check(rows, cols):
global Q
h = -1
for r in rows:
for c in cols:
if L[r][c] > h:
V[r * W + c] = True
h = L[r][c]
Q += 1
V = [False for _ in range(size)]
for r in range(H):
check([r], range(W))
check([r], range(W-1, -1, -1))
for c in range(W):
check(range(H), [c])
check(range(H-1, -1, -1), [c])
print(sum(V), 2*(H*W+W*H), Q)