From f85949f85266768ec1bd5e3d150e4ac71feabcf1 Mon Sep 17 00:00:00 2001 From: boredpasta Date: Mon, 13 Jan 2025 07:00:52 +0200 Subject: Add project files --- 2022/08/a.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 2022/08/a.py (limited to '2022/08/a.py') 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) -- cgit v1.2.3