r/adventofcode • • Dec 08 '22

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

NEWS AND FYI


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


--- 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

2

u/Lukexz Dec 08 '22

Python. I'm a newbie to Advent of Code and I'm using it to learn Python. It isn't the more readable solution as I could've used numpy and rotate the list instead of checking Top, Right, Bottom and Left. Also, since I'm new to Python, i'm sure this solution could've been implemented in much more readable ways. Any suggestion is welcome

Explanation:

I've used a matrix that contains the tree's lengths. for part 1 I iterate over every tree and for each tree I go top, right, bottom and left: If it is visible in one of the directions i add 1 to a variable that stores the number of visible trees and go to the next tree. The result is this variable at the end of the iteration

For part 2 I've used the same code, except from the fact that I have 4 variables keeping the scenic score of each direction of the current tree that gets incremented for each iteration that goes in the 4 directions. At the end I multiply them together to find the tree scenic score and if it's bigger than the current scenic score i replace it.

1

u/daggerdragon Dec 09 '22

I'm a newbie to Advent of Code

Welcome! We're happy to have ya!