You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Solution: Part one was a bunch of math, wherein I figured out how the pattern repeats and grows. Part two I had to simulate. I used the Complex Numbers trick to make tracking the direction easy.
Problem: Moving values around an array, and tracking repeating patterns.
Solution: All my work with modulo math to loop lists helped here. A hash function and HashSet() kept uniqueness in check. Part two added another tracker in the form of a list to track indexes with.
Solution: Straightforward puzzle. I played with the CSharpScripting() class, and while it worked, the performance of compiling code every loop wasn't great. I fell back to a basic switch statement.
Problem: Calculate the distance of spot on a hex grid.
Solution: This took a bunch of visualization and spreadsheet work, followed by a pile of debugging moving around negative hex numbers. I learned that modulo of a negative number will return a negative.
Solution: This turned into a recursive call to fill a Dictionary(). When I ran out of items, I stepped through the puzzle until I found a new entry point.
Problem: Run a set of instructions over an array, then do it a billion times.
Solution: I made a single pass at brute forcing part two, however, the instructions are too complex to make that work. Instead I ran a test to see if the pattern repeats, which it did. One modulo calculation later, and that was that.
Solution: Part one was a straight forward VM implementation. Part two required reworking all of that into a class, and then running two of them side by side. I used the main program loop to pass values back and forth until they deadlocked.
Problem: Calculating the position and collisions of particles.
Solution: For part one, it appears that I need to brush up on my physics. I solved both parts via a simulation. Point3D() got dusted off and extended with GetHashCode() to make it work in GroupBy() calls. That was a rabbit hole.
Solution: I pre-rotated and flipped the key values to expand the dictionary rules. This saved me from doing that operation for each bit in the puzzle itself. My initial solution developed with an array of string to represent the puzzle data. I replaced that with a one dimensional array of bool for an approx 2.5 - 3x performance improvement. (~650 ms -> ~250 ms)
Problem: Track the state of a grid as a bot moves across it.
Solution: Hey, have you heard about Complex Numbers? They're great at tracking bot positions. Also, passing by ref when one expects by value is a great way to introduce bugs. Note to future self, reverse the array before it gets passed to the worker function, not after.
Problem: Debug and decode an inefficient program that runs on the Day 18 VM.
Solution: Lots of fiddling by re-implementing the program in a scratch project. The program is calculating if a range of numbers are prime. Stack Overflow provided some better code to calculate primes.
Problem: One last puzzle to track symbols on a line.
Solution: The tricky part was to parse the puzzle input. I had some really dense syntax initially, which I replaced afterwards with something more sane. A fun puzzle to finish off the year.