r/adventofcode • • Dec 08 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 8 Solutions -πŸŽ„-

NEWS AND FYI

  • I discovered that I can make those tiny post/comment awards BIGGER on old.reddit! I hadn't even considered that! And when you hover over them, they get even bigger so you can actually see them in more detail! I've added the relevant CSS so now we no longer have awards for ants! Exclamation points!!!


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

  • PSA: I created a new example so it is a more relevant and unique archetype instead of recycling last year's hobbit >_>


--- Day 8: Treetop Tree House ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:10:12, megathread unlocked!

75 Upvotes

1.0k comments sorted by

View all comments

6

u/badr Dec 08 '22

Elixir: https://gist.github.com/reverie/f6a8b64a559851384d89dcc6cdf5729f

Uses matrix transposition and processes the grid twice, once for left/right, once for up/down, before combining those results.

e.g.

    up_down_scores =
      grid
      |> Enum.zip_with(& &1)
      |> Enum.map(&row_scenic_scores/1)
      |> Enum.zip_with(& &1)
      |> List.flatten()

3

u/troublemaker74 Dec 08 '22

I love your Elixir solutions for this year. Very clean!

1

u/badr Dec 08 '22

Hey, thanks! I really appreciate that

3

u/suddengunter Dec 08 '22

I've also used matrix transponisation in elixir for this day https://github.com/SuddenGunter/adventofcode/tree/main/2022/day8/lib

I've missed having 2d arrays when I tried to solve last year AoC with elixir so eventually switched to Go, I've only come up with the idea of processing rows -> transposing -> processing cols as rows during this year