Skip to content

pablolessa/AOC2024

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2024: 50 Shades of Dijkstra

I had heard of a Advent of code a few years back but had never tried to complete it.

With limited time available I solved about 12 problems before Christmas, but then enjoyed completing the rest during my summer vacation (yep, summer, I'm in the southern hemisphere). It was a lot of fun.

Here are some observations and conclusions I take away from the experience:

  • AIs are apparently really good at this type of thing. I had no idea. Most problems that AIs solved in under 30 seconds would take me half an hour to an hour, or sometimes more. The problems that were hard for the AIs, I also struggled with.
  • Some humans are really good at this type of thing. Sometimes, after solving a problem I would go watch Jonathan Paulson solve it on youtube. Usually the process would be very similar to mine (I was also using Python), but at 5 to 10 times the speed. I should say that sometimes this was not the case. For example problem 17 part two took me several days. I spent a lot of time trying to make my simulations run quickly whereas Jonathan got to the heart of the matter in minutes.
  • On the subject of performance I usually would run Scalene on any solution taking more than 20 to 30 seconds. It was very informative. For example on problem 22 part 2, for some reason I decided to keep a dictionary of Bools, which indicated if a certain pattern had appeared or not in a list of price differences. Scalene indicated that most of my time was spent initializing this to False at the start of each sequence I wanted to analyze. Then I realized that I was simulating a set with a bunch of Bools for no reason. The trivial change of making this an actual set made the program run in under a second, instead of several dozen seconds. I mad similar mistakes in a couple of other problems.
  • Adding @cache to a recursive functions is a magic trick! I knew about this from way back when people would put a named argument containing a dictionary to cache results. But I'm still surprised how effective this was on several of the problems (e.g. problems 11, 19, and 21).
  • I recognized Problem 23 part 2 as the "clique problem" from computational graph theory. After checking wikipedia I essentially implemented the Bron-Kerbosch algorithm adapting it from the pseudo-code on the page. It was nice to learn about this "brute-force" but elegant algorithm.
  • For Problem 24 part 2 I realized I had never actually studied or done anything with circuit logic. After reading a bit about logic optimization (they lost me at "prime implicants"), I decided to make a program to output the circuit as a pdf using GraphViz (that I had used before). This immediatly showed me that z18 was one of the four mistakes. So I looked at the adder circuit on wikipedia and followed the circuit "by hand" a little bit to find the mistake on z07. After this I wrote a small program to test inputs fiddling with only a few bits of x and y. Basically this allowed me to find the remaining two mistakes and fix them. It was pretty satisfying to learn how adder circuits work and work this out visually, though I probably missed out on learning some nice algorithms that exist in this context.
  • I found that quite a few problems could be reformulated as finding the shortest path between two vertices in a graph, or some variant of this. Hence, I think the title "50 shades of Dijkstra" sums up my experience with AOC pretty well. I wonder how far writting a small script to actually build a graph in a format acceptable by some program that knows about such things would get you in 2024 AOC.
  • One time the graph point of view got me in trouble. In problem 21 I assumed I was calculating a distance in a graph, and that this distance was symmetric i.e. dist(x,y) = dist(y,x). For directed graphs, this property is not true, and in this particular instance my program gave the wrong answer because of this assumption.
  • I really need to learn to use a debugger better. Inserting breakpoint() at a critical portion of the program and just hitting "n" and evaluating different expressions worked wonders for me. But several times I was frustrated interacting with (Pdb) on the command line. For example, I dont think it allows you to define your own functions live. And I couldn't figure out how to avoid having to retype a full line after making a mistake trying to evaluate some complicated expression.

24graph.dot.pgn

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages