My (attempted) solutions to the 2022 Advent of Code
Log | Files | Refs | README

```commit 3124dadd09fe9eedf3d9eab85596ceb4dc99c74d
parent cdeecb07c7c3a9194aafef271d63047008f23d13
Date:   Thu,  8 Dec 2022 10:14:22 -0800

Solution to day 8, part 2.

Diffstat:
Msrc/day_8.jl | 25++++++++++++++++++++++++-
```
```1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/src/day_8.jl b/src/day_8.jl
@@ -52,7 +52,30 @@ end
@assert part_1(example) == 21
@info part_1(input)

+# Find the component of a scenic score looking along one direction
+function score_component(treeheight::Int, neighbortrees::Vector{Int})::Int
+    trees_seen = findfirst(x->x>=treeheight, neighbortrees)
+    if trees_seen == nothing
+        trees_seen = length(neighbortrees)
+    end
+    trees_seen
+end
+
function part_2(input)
-    nothing
+    trees = parse_input(input)
+    mapheight, mapwidth = size(trees)
+    scenicscore = fill(0, (mapheight, mapwidth))
+
+    for (row, col) = Iterators.product(2:mapheight-1, 2:mapwidth-1)
+        scenicscore[row, col] = mapreduce(
+            Base.Fix1(score_component, trees[row, col]),
+            *,
+            (trees[row, col-1:-1:1], trees[row, col+1:end],
+             trees[row-1:-1:1, col], trees[row+1:end, col])
+        )
+    end
+
+    maximum(scenicscore)
end
+@assert part_2(example) == 8
@info part_2(input)
```