day 8, imperative way, ugly but works
This commit is contained in:
parent
37f0f25dec
commit
3c39e0e147
|
@ -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)
|
|
@ -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)
|
Loading…
Reference in New Issue