r/adventofcode • u/clbrri • Dec 22 '22
Spoilers [2022 Day 22 Part 2] Video analysis for solving algorithm for second part
Hi all,
thanks for a really wacky puzzle for day 22. This was the most enjoyable for me so far! <3
I created a video that details an algorithm I came up with for solving the cube folding patterns without hardcoding the coordinate mappings. Check it out here: https://youtu.be/qWgLdNFYDDo (22 min 33 seconds)
I don't know if there exists a simpler method, let me know if there is needless complexity there :)
Or if you just want to look at code, here is commented code for a python solver: https://gist.github.com/juj/1f09f475e01949233a2f206a0552425c
(I did not actually use the algorithm in my solution, but came up with it while already being overcommitted to hardcoding the mappings as well :D) You can find the massively long 3h video stream here: https://www.twitch.tv/videos/1685732073 to see how nasty solving it via hardcoding the mappings gets :>), and my original solution at https://www.reddit.com/r/adventofcode/comments/zsct8w/comment/j18acks/
2
u/Mahrgell2 Dec 22 '22
Just wanted to say thank you for posting readable well structured code. Such a rare sight these days :)
2
u/taylorott Dec 23 '22
My solution was basically identical to what you presented in the video. However, I didn't think of the edge case that you pointed (great catch!), so currently my solver cannot handle it. I'm going to need to update my solver to fix that!
2
u/Gobbel2000 Dec 22 '22
I like it, that's a neat way of folding it up, although that one edge case shape feels quite annoying.
The solution I came up with to generalize for any unfolding was to first just walk through the input square by square to assign a grid for each of the cube's faces. Then for the transitions I just wrote down all combinations of faces and movement directions to figure out where you'd land next. But I kind of like this way more, just because it doesn't involve so much hardcoding with the transition table.
1
u/AhegaoSuckingUrDick Jan 04 '23
I used a different approach for an arbitrary net. Start by computing what the "horizontal" and "vertical" axes are for each face in the net. A move on the net is the same as rotation alongside the corresponding axis for the current face. When we need to jump from one face to another, compute the normal of the resulting face alongside with the new axes (the expected axes if the new face were adjacent to the old one). Then we can determine the rotation from the difference between the expected axes and actual ones (precomputed for the current net in the first step).
See my Python implementation for details.