diff options
author | boredpasta <boredpasta@tutanota.com> | 2025-01-13 07:00:52 +0200 |
---|---|---|
committer | boredpasta <boredpasta@tutanota.com> | 2025-01-13 07:22:23 +0200 |
commit | f85949f85266768ec1bd5e3d150e4ac71feabcf1 (patch) | |
tree | a6c81c5ec164d209bf0e664d6a6a22ddd42cd63f /2022/08/a.py | |
parent | af9283db3825dbfede0a4127a004f0b077fe6f7c (diff) |
Diffstat (limited to '2022/08/a.py')
-rw-r--r-- | 2022/08/a.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/2022/08/a.py b/2022/08/a.py new file mode 100644 index 0000000..f762554 --- /dev/null +++ b/2022/08/a.py @@ -0,0 +1,42 @@ +def is_visible(i, j): + this = grid[i][j] + surround = [ + [grid[i2][j] for i2 in range(i)], + [grid[i][j2] for j2 in range(j)], + [grid[i2][j] for i2 in range(i+1, len(grid))], + [grid[i][j2] for j2 in range(j+1, len(grid[0]))], + ] + return any([all([s < this for s in sur]) for sur in surround]) + +def view(i, j): + score = 1 + this = grid[i][j] + surround = [ + [grid[i2][j] for i2 in range(i-1, -1, -1)], + [grid[i][j2] for j2 in range(j-1, -1, -1)], + [grid[i2][j] for i2 in range(i+1, len(grid))], + [grid[i][j2] for j2 in range(j+1, len(grid[0]))], + ] + for sur in surround: + surlen = len(sur) + i = 0 + while i < surlen and sur[i] < this: + i += 1 + if i < surlen and sur[i] >= this: + i += 1 + score *= i + return score + + +#with open("example") as f: +with open("input") as f: + grid = [line.strip() for line in f.readlines()] +width, height = len(grid[0]), len(grid) +edge_visible = (width + height-2) * 2 +highest = 0 +for i in range(1, height-1): + for j in range(1, width-1): + score = view(i, j) + if score > highest: + highest = score +print(highest) |