This commit is contained in:
2022-12-08 18:40:29 +02:00
parent c9314ad089
commit 6c48e11b47
2 changed files with 18890 additions and 27 deletions

87
08/h.py
View File

@@ -12,44 +12,77 @@ for l in input:
tmp.append([int(x), False])
trees.append(tmp)
height_ = len(trees)
width = len(trees[0])
rows = len(trees)
cols = len(trees[0])
# for x in range(0, height_, 1):
# print(trees[x])
for x in range(0, width, 1):
def calcScore(x: int, y: int):
h = trees[y][x][0]
ls, rs, us, ds = 1, 1, 1, 1
# right
i = x+1
while (i < cols-1 and trees[y][i][0] < h):
i += 1
rs += 1
# left
i = x-1
while (i > 0 and trees[y][i][0] < h):
i -= 1
ls += 1
# down
i = y+1
while (i < rows - 1 and trees[i][x][0] < h):
i += 1
ds += 1
# up
i = y-1
while (i > 0 and trees[i][x][0] < h):
i -= 1
us += 1
return ls*rs*us*ds
scenic_scores = []
for x in range(0, cols, 1):
height = 0
for y in range(0, width, 1):
if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1):
trees[x][y][1] = True
height = trees[x][y][0]
for y in range(0, cols, 1):
if trees[y][x][0] > height or (x == 0) or (y == 0) or (x == cols-1) or (y == rows-1):
trees[y][x][1] = True
height = trees[y][x][0]
height = 0
for y in range(width-1, -1, -1):
if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1):
trees[x][y][1] = True
height = trees[x][y][0]
for y in range(cols-1, -1, -1):
if trees[y][x][0] > height or (x == 0) or (y == 0) or (x == cols-1) or (y == rows-1):
trees[y][x][1] = True
height = trees[y][x][0]
for y in range(0, height_, 1):
for y in range(0, rows, 1):
height = 0
for x in range(0, height_, 1):
if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1):
trees[x][y][1] = True
height = trees[x][y][0]
for x in range(0, cols, 1):
if trees[y][x][0] > height or (x == 0) or (y == 0) or (x == cols-1) or (y == rows-1):
trees[y][x][1] = True
height = trees[y][x][0]
if (x != 0) and (y != 0) and (x != cols-1) and (y != rows-1):
scenic_scores.append(calcScore(x, y))
height = 0
for x in range(height_-1, -1, -1):
if trees[x][y][0] > height or (x == 0) or (y == 0) or (x == width-1) or (y == height_-1):
trees[x][y][1] = True
height = trees[x][y][0]
for x in range(cols-1, -1, -1):
if trees[y][x][0] > height or (x == 0) or (y == 0) or (x == cols-1) or (y == rows-1):
trees[y][x][1] = True
height = trees[y][x][0]
tot = 0
for x in range(0, height_, 1):
# print(trees[x])
for y in range(0, width, 1):
if trees[x][y][1]:
for y in range(0, rows, 1):
for x in range(0, cols, 1):
if trees[y][x][1]:
tot += 1
print(tot)
print("Part 1: " + str(tot))
print("Part 2: " + str(max(scenic_scores)))

18830
08/output.txt Normal file

File diff suppressed because it is too large Load Diff