day 8, imperative way, ugly but works

This commit is contained in:
setop 2022-12-08 12:44:02 +01:00
parent 37f0f25dec
commit 3c39e0e147
2 changed files with 50 additions and 0 deletions

17
d08/part1.py Normal file
View File

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

33
d08/part2.py Normal file
View File

@ -0,0 +1,33 @@
import sys
L = list(list(map(int,s)) for s in sys.stdin.read().splitlines())
W = len(L[0]) ; H = len(L)
S=0
for i in range(H):
for j in range(W):
v = L[i][j]
# look right
r = 0
for k in range(j+1, W):
r += 1
if L[i][k]>=v:
break
# look left
l = 0
for k in range(j-1,-1,-1):
l+=1
if L[i][k]>=v:
break
# look up
u = 0
for k in range(i-1,-1,-1):
u+=1
if L[k][j]>=v:
break
# look down
d = 0
for k in range(i+1,H):
d += 1
if L[k][j]>=v:
break
S = max(S,r*l*u*d)
print(S)