:: krowemoh

Thursday | 26 DEC 2024
Posts Links Other About Now

previous
next

Advent of Code 2023 - Day 4

2023-12-04
advent-of-code, basic

Today's puzzle was very easy. The core idea was to get the intersection of 2 lists. I think writing a intersection routine might be fun but I did it the dumb way.

Part 2 was much more difficult in that it was hard to understand but once I figured out what it was trying to do then it was straightforward.

The funnest thing here was that originally I wrote the code as brain dead as possible and when I ran it the program hanged. I then put a print statement to log each line and I realized that I wasn't getting into a infinite loop so much as I was just taking a really long time to process things.

My algorithm had way too many nested loops and I think I hit O(n^3). I changed the BASIC multivalue string to a dimensioned array and this went much faster but still took long.

I then fixed the algorithm so that it was O(n). This was actually a very quick change as I realized once I looked at the code that I was using a for loop to do multiplication. That was what made today so fun! That feeling of realizing that I had just used loops to implement multiplication was hilarious.

Day 4 Answer