You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
73 lines
2.0 KiB
with open('input8.txt','r') as f: |
|
inp = f.read().splitlines(keepends=False) |
|
|
|
grid = [] |
|
visible = 0 |
|
scenicScore = 0 |
|
|
|
for y in range(len(inp)): |
|
grid.append([]) |
|
for x in inp[y]: |
|
grid[y].append(int(x)) |
|
|
|
colLeng = len(grid) - 1 |
|
rowLeng = len(grid[0]) - 1 |
|
|
|
for y in range(len(grid)): |
|
for x in range(len(grid[y])): |
|
if y == 0 or y == colLeng or x == 0 or x == rowLeng: |
|
visible += 1 |
|
else: |
|
tempb = 0 |
|
tempa = grid[y][x] |
|
for i in range(y): |
|
if grid[i][x] >= tempa: |
|
tempb += 1 |
|
break |
|
for i in range(x+1, rowLeng + 1): |
|
if grid[y][i] >= tempa: |
|
tempb += 1 |
|
break |
|
for i in range(y+1, colLeng + 1): |
|
if grid[i][x] >= tempa: |
|
tempb += 1 |
|
break |
|
for i in range(x): |
|
if grid[y][i] >= tempa: |
|
tempb += 1 |
|
break |
|
if tempb != 4: |
|
visible += 1 |
|
|
|
print("Number of visible trees", visible) |
|
|
|
for y in range(len(grid)): |
|
for x in range(len(grid[y])): |
|
if y == 0 or y == colLeng or x == 0 or x == rowLeng: |
|
continue |
|
tempa = 0 |
|
tempb = 0 |
|
tempc = 0 |
|
tempd = 0 |
|
tempcord = grid[y][x] |
|
for i in range(y - 1, -1,-1): |
|
tempa +=1 |
|
if grid[i][x] >= tempcord: |
|
break |
|
for i in range(x+1, rowLeng + 1): |
|
tempb += 1 |
|
if grid[y][i] >= tempcord: |
|
break |
|
for i in range(y+1, colLeng + 1): |
|
tempc += 1 |
|
if grid[i][x] >= tempcord: |
|
break |
|
for i in range(x- 1, -1, -1): |
|
tempd += 1 |
|
if grid[y][i] >= tempcord: |
|
break |
|
score = tempa * tempb * tempc * tempd |
|
if score > scenicScore: |
|
scenicScore = score |
|
|
|
print("higest Viewscore", scenicScore) |