aboutsummaryrefslogtreecommitdiff
path: root/2022/08/solve.py
diff options
context:
space:
mode:
authorMarvin Borner2022-12-08 07:09:22 +0100
committerMarvin Borner2022-12-08 07:09:22 +0100
commit01722b35f1101358077481008c998fb84867c928 (patch)
treec9f2250ab678329598096c0c7a8635d5c24ea5f3 /2022/08/solve.py
parent1da4f10f68255fe5ddae10b30106c42372c261a0 (diff)
uff
Diffstat (limited to '2022/08/solve.py')
-rw-r--r--2022/08/solve.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/2022/08/solve.py b/2022/08/solve.py
new file mode 100644
index 0000000..b9f5947
--- /dev/null
+++ b/2022/08/solve.py
@@ -0,0 +1,53 @@
+data = [list(dat.strip()) for dat in open("input").readlines() if dat != '']
+
+def part1():
+ res = 0
+ for i in range(1,len(data)-1):
+ for j in range(1,len(data[0])-1):
+ sight = [True,True,True,True]
+
+ for l in range(0, i):
+ if data[l][j] >= data[i][j]:
+ sight[0] = False
+ for l in range(0, j):
+ if data[i][l] >= data[i][j]:
+ sight[1] = False
+ for l in range(len(data[0])-1,j,-1):
+ if data[i][l] >= data[i][j]:
+ sight[2] = False
+ for l in range(len(data)-1,i,-1):
+ if data[l][j] >= data[i][j]:
+ sight[3] = False
+ if any(sight):
+ res += 1
+
+ return res + ((len(data)+len(data[0]))*2-4)
+
+def part2():
+ res = []
+ for i in range(1,len(data)-1):
+ for j in range(1,len(data[0])-1):
+ sight = [0,0,0,0]
+
+ for l in range(i-1, -1, -1):
+ sight[0] += 1
+ if data[l][j] >= data[i][j]:
+ break
+ for l in range(j-1, -1, -1):
+ sight[1] += 1
+ if data[i][l] >= data[i][j]:
+ break
+ for l in range(j+1, len(data[0])):
+ sight[2] += 1
+ if data[i][l] >= data[i][j]:
+ break
+ for l in range(i+1, len(data)):
+ sight[3] += 1
+ if data[l][j] >= data[i][j]:
+ break
+ res.append([x:=1,[x:=x*s for s in sight]][-1][-1]) # Woah!
+
+ return max(res)
+
+print(f"Part 1: {part1()}")
+print(f"Part 2: {part2()}")