All I had to do to solve part 2 of yesterday's puzzle was to swap out the ArrayList
my data structure was based on for a LinkedList
The problem was that my data structure has two constructors and I only swapped it out in one of them. I assumed I was using a LinkedList and couldn't understand why it was taking so long. I even fired up my profiler only to find out that the NetBeans profiler doesn't work with Java 9+. Eventually I let it run the entire night and this morning I found out that after running for 10(!) hours, it had given me the incorrect answer because I used int
instead of long
After thinking about it for a bit today, I couldn't imagine that the list was so slow, and that's when I found out my mistake. *Actually* using the LinkedList reduced the runtime from 10 hours to a bit over a second.
I really liked that one, because it's the first real example I've seen of a case where a LinkedList
greatly outperforms an ArrayList
Today's puzzle was also really fun. I just let it run until the bounding rectangle of the points has a height and width that fits on my screen and then I visually inspect the message. Sadly it doesn't work well with the testing framework I wrote for AoC, unless I extended my solution with some sort of optical character recognition.