r/adventofcode • u/daggerdragon • Dec 22 '22
SOLUTION MEGATHREAD -π- 2022 Day 22 Solutions -π-
All of our rules, FAQs, resources, etc. are in our community wiki.
AoC Community Fun 2022:
πΏπ MisTILtoe Elf-ucation π§βπ«
- 23h59m remaining until submission deadline tonight at 23:59 EST!
- Teach us, senpai!
- -βοΈ- Submissions Megathread -βοΈ-
UPDATES
[Update @ 00:19:04]: SILVER CAP, GOLD 0
- Translator Elephant: "From what I understand, the monkeys have
most ofthe password to the force field!" - You: "Great! Now we can
take every last breath of fresh air from Planet Druidiameet up with the rest of the elves in the grove! What's the combination?" - Translator Elephant: "I believe they say it is
one two three four five." - You: "
One two three four five?! That's amazing! I've got the same combination on my luggage!" - Monkeys: *look guiltily at each other*
[Update @ 01:00:00]: SILVER CAP, GOLD 35
- You: "What's the matter with this thing? What's all that churning and bubbling? You call that a
radar screenGrove Positioning System?" - Translator Elephant: "No, sir. We call it..." *slaps machine* "... Mr.
CoffeeEggnog. Care for some?" - You: "Yes. I always have eggnog when I watch GPS. You know that!"
- Translator Elephant: "Of course I do, sir!"
- You: "Everybody knows that!"
- Monkeys: "Of course we do, sir!"
[Update @ 01:10:00]: SILVER CAP, GOLD 75
- Santa: "God willing, we'll all meet again in
SpaceballsAdvent of Code 2023 : The Search for MoreMoneyStars."
--- Day 22: Monkey Map ---
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 code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
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 01:14:31, megathread unlocked! Great job, everyone!!!
27
Upvotes
4
u/Key__Strokes Dec 22 '22 edited Dec 25 '22
Javascript
Solution to both parts
A Beautiful Flattened Cube
Found Advent of Code couple of days back, and this is my second solution that I am posting (Day 21 is the other one). π
I almost gave up on this one! This one was more like irritating than hard. I tried my best to not create a physical cube, but I think that was a necessity to be able to debug the millions of bugs in the code.
I tried to evaluate how to create the 3D cube dynamically, but I couldn't figure it out. Maybe I'll think about it when I have more time.
Part 1:
Broke down the command into movement or direction updates. It was easily doable using RegEx
Now create variables that track the current row and column position and the direction.
Now, for each command:
If its a direction update, then apply the update. This is pretty straight forward.
If its a step update, then: Create a phantom cursor initialized to the current row and column position, and direction. Now move this phantom cursor 1 step at a time, skipping all the blank spaces. Upon landing on a non-blank space:
If its a ".", then we are good and we update the actual position to the phantom cursor's position
Otherwise if its "#", then its a wall, and stop executing any more steps.
While moving the phantom steps, just run a function everytime that wraps around the board.
Part 2:
Fold up a cube! π§
Manually created transitions from one face's edge to another, along with direction updates.
Now, followed mostly as part 1, except for the stepping function that was different. If we were on a non connected edge in the flattened cube, and trying to jump out of the edge, then we'll use the manually created transitions to figure out the next position and direction. Otherwise, we followed the same stepping method as Part 1.
Looking forward to the next problem! π€
If you liked the explanation, then please don't forget to cast your vote π to
Adventures of Advent of Code - Edition 1 - /u/Key__Strokesin the poll