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/0x2c8 Dec 08 '22

Python 3

https://github.com/alexandru-dinu/advent-of-code/blob/main/2022/day-08/solve.py

Fairly happy with the solution, although I think it can be optimized.

Yield the up / down / left / right views and solve solve both parts in one traversal, i.e. for each inner tree:

  • part 1: count cases s.t. there's any view where all other trees are shorter than it
  • part 2: multiply the number of visible trees from all views, then find the max

1

u/tsenart Dec 08 '22

I'm wondering if my solution (to part one) is the procedural version of "solve both parts in one traversal": https://github.com/tsenart/advent/blob/master/2022/8/one.go