day 9 short
This commit is contained in:
parent
0849c2a1e2
commit
edd0059e7e
16
d09/d09_1.py
16
d09/d09_1.py
|
@ -3,23 +3,9 @@ L = list(map(lambda s: [9]+list(map(int, s))+[9] ,sys.stdin.read().splitlines())
|
||||||
W = len(L[0])
|
W = len(L[0])
|
||||||
L = [[9]*W] + L + [[9]*W]
|
L = [[9]*W] + L + [[9]*W]
|
||||||
H = len(L)
|
H = len(L)
|
||||||
|
|
||||||
def printgrid():
|
|
||||||
for row in L:
|
|
||||||
print("".join(map(str,row)))
|
|
||||||
|
|
||||||
printgrid()
|
|
||||||
S = 0
|
S = 0
|
||||||
for x in range(1,H-1):
|
for x in range(1,H-1):
|
||||||
for y in range(1,W-1):
|
for y in range(1,W-1):
|
||||||
p = L[x][y]
|
p = L[x][y]
|
||||||
n = L[x-1][y]
|
S += (p+1) * all(p<L[x+i][y+j] for (i,j) in [(0,1),(1,0),(-1,0),(0,-1)])
|
||||||
s = L[x+1][y]
|
|
||||||
e = L[x][y-1]
|
|
||||||
w = L[x][y+1]
|
|
||||||
islow =all([p<n,p<s,p<e,p<w])
|
|
||||||
print(x,y,p,n,s,e,w)
|
|
||||||
if islow:
|
|
||||||
print(x,y,p, "is low")
|
|
||||||
S+= p+1
|
|
||||||
print(S)
|
print(S)
|
||||||
|
|
35
d09/d09_2.py
35
d09/d09_2.py
|
@ -6,33 +6,20 @@ H = len(L)
|
||||||
def printgrid():
|
def printgrid():
|
||||||
for row in L:
|
for row in L:
|
||||||
print("".join(map(str,row)))
|
print("".join(map(str,row)))
|
||||||
def neigh(x,y,C=0,V=set()):
|
def neigh(x,y,W:set):
|
||||||
p = L[x][y]
|
p = L[x][y]
|
||||||
if p<9:
|
if p<9:
|
||||||
V.add((x,y))
|
W.add((x,y))
|
||||||
C+=1
|
|
||||||
#print(' '*C, x,y,"p="+str(p), C)
|
|
||||||
for (i,j) in [(0,1),(1,0),(-1,0),(0,-1)]:
|
for (i,j) in [(0,1),(1,0),(-1,0),(0,-1)]:
|
||||||
if L[x+i][y+j]>p and (x+i,y+j) not in V:
|
if L[x+i][y+j]>p and (x+i,y+j) not in W:
|
||||||
C=neigh(x+i,y+j,C,V)
|
neigh(x+i,y+j,W)
|
||||||
return C
|
#printgrid()
|
||||||
else:
|
|
||||||
#print(' '*C, x,y,"p="+str(p), C)
|
|
||||||
return C
|
|
||||||
printgrid()
|
|
||||||
S = []
|
S = []
|
||||||
for x in range(1,H-1):
|
for x in range(1,H-1):
|
||||||
for y in range(1,W-1):
|
for y in range(1,W-1):
|
||||||
p = L[x][y]
|
V = set()
|
||||||
n = L[x-1][y]
|
neigh(x,y,V)
|
||||||
s = L[x+1][y]
|
S.append(len(V))
|
||||||
e = L[x][y-1]
|
#print(V)
|
||||||
w = L[x][y+1]
|
#print(S)
|
||||||
islow =all([p<n,p<s,p<e,p<w])
|
print(sorted(S)[-3:])
|
||||||
#print(x,y,p,n,s,e,w)
|
|
||||||
if islow:
|
|
||||||
print(x,y,p, "is low")
|
|
||||||
S.append(neigh(x,y))
|
|
||||||
print(S)
|
|
||||||
S = sorted(S)
|
|
||||||
print(S[-1]*S[-2]*S[-3])
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
print("""P2
|
||||||
|
100 100
|
||||||
|
9""")
|
||||||
|
import sys
|
||||||
|
for l in sys.stdin.read().splitlines():
|
||||||
|
for c in l:
|
||||||
|
print(9-int(c))
|
Loading…
Reference in New Issue