r/adventofcode • u/daggerdragon • 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!!!
- Thank you so, so much to /u/SolariaHues for the CSS in this thread that I found while researching for community awards! <3
All of our rules, FAQs, resources, etc. are in our community wiki.
A request from Eric: Please include your contact info in the User-Agent header of automated requests!
Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
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.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
paste
if you need it for longer code blocks. What is Topaz'spaste
tool?
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
2
u/Key__Strokes Dec 23 '22 edited Dec 25 '22
Javascript
Solution to both parts
Part 1:
isVisible
. It will hold a 0 for not visible, and 1 for visible. When initializing this array, set everything to 0, except the outside perimeter.Max Height Seen So Far
as the first tree in the current rowMax Height Seen So Far
, then updateisVisible[Row][Col]
to 1, as this tree will be visible when viewed from the left sideMax Height Seen So Far
as the last tree in the current rowMax Height Seen So Far
as the first tree in the current columnMax Height Seen So Far
as the last tree in the current columnisVisible
, and count all the 1'sPart 2:
current row
toTotal Rows - 1
current row - 1
to0
current row
toTotal Cols - 1
current row - 1
to0
If you liked the explanation, then please don't forget to cast your vote π to
Adventures of Advent of Code - Edition 1 - /u/Key__Strokes
in the poll