summaryrefslogtreecommitdiff
path: root/2022/08/a.py
diff options
context:
space:
mode:
Diffstat (limited to '2022/08/a.py')
-rw-r--r--2022/08/a.py42
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)