8-2
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
map = []
|
||||
def directionScore(x, y, tree):
|
||||
score = 0
|
||||
if type(x) == range: # Horizontal
|
||||
for i in x:
|
||||
score += 1
|
||||
if map[y][i] >= tree:
|
||||
break
|
||||
elif type(y) == range: # Vertical
|
||||
for i in y:
|
||||
score += 1
|
||||
if map[i][x] >= tree:
|
||||
break
|
||||
return score
|
||||
|
||||
with open("input.txt", "r") as f:
|
||||
for line in f.readlines():
|
||||
map.append(list(line.strip()))
|
||||
H = len(map)
|
||||
W = len(map[0])
|
||||
|
||||
biggestScore = 0
|
||||
for y in range(H):
|
||||
for x in range(W):
|
||||
tree = map[y][x]
|
||||
score = (directionScore(x, range(y-1, -1, -1), tree) * # Up
|
||||
directionScore(x, range(y+1, H), tree) * # Down
|
||||
directionScore(range(x-1, -1, -1), y, tree) * # Left
|
||||
directionScore(range(x+1, W), y, tree)) # Right
|
||||
if score > biggestScore:
|
||||
biggestScore = score
|
||||
print(biggestScore)
|
||||
Reference in New Issue
Block a user