Advent of Code 2022 - Day 14

preview_player
Показать описание
I'm trying to solve this video series's Advent of Code puzzles.

Git repository:

Unlock unlimited opportunities with 50% off your first month of Coursera Plus

Get on the fast track to a career in cybersecurity. In this certificate program, you'll learn in-demand skills, and get AI training from Google experts. Learn at your own pace, no degree or experience required.

Boost your software development career with Gen AI. Build in-demand, hands-on, Generative AI skills for elevating your software engineering game in 1 month or less.

NordPass - We lock passwords. You hold the key.

NordPass - 50% off the Premium plan

Linode - Cut Your Cloud Bills in Half

Join the channel to get access to more perks:

Or visit my blog at:

Outro music: Sanaas Scylla

#adventofcode #aoc #java
Рекомендации по теме
Комментарии
Автор

Because we didn't know the range we would have to work with (short of sorting through the input data), I stored my cave data in a Map of (x, y) -> occupied state. Occupied state could have been a boolean, but I decided to keep track of whether it's occupied by rock or sand, so that I could visualize it for debugging. By using a Map (and keeping track of the min/max x and y values) I didn't need to worry about reserving enough space, and I had a feeling (which turned out to be unfounded) that Part B would blow up the play field to an unmanageable size. I used a similar method to you to fill in the lines in the map, then while simulating the falling sand, "map.contains(Pair(x, y))" tells me whether the position is occupied or free. Overall I think I ended up with a similar solution.

For Part B I was trying to get it to work without drawing in the floor, but I couldn't get the calculation to work properly, so I ended up drawing in a floor from (lowestX-1000) to (highestX+1000) and then essentially using the same algorithm as Part A, with the change to stop once the hole got plugged. This was a fun challenge.

aaronperl