aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

README.md (3681B)


      1 # Advent of Code 2025
      2 
      3 Run with Python. Input is read from the file given as argument, or
      4 from standard input if no argument is provided.
      5 
      6 Example
      7 
      8 `python 01/a.py 01/input.txt`
      9 
     10 ## Personal times
     11 
     12 ```
     13 Day   -Part 1-   -Part 2-
     14   7   00:05:27   00:20:40
     15   6   00:13:38   01:49:24
     16   5   00:04:39   00:22:19
     17   4   00:25:36   00:27:49
     18   3   00:05:02   00:16:09
     19   2   00:10:36   00:11:55
     20   1   00:06:20   00:50:41
     21 ```
     22 
     23 ## Daily comments (spoilers!)
     24 
     25 ### Day 1: Secret Entrance
     26 
     27 Part 1 was easy. Well, I misread the statement and got it wrong twice,
     28 but that's on me.
     29 
     30 Then I kept getting part 2 wrong, and I have no idea what I was doing wrong.
     31 Sure, at first I made some mistakes related to landing on zero at the
     32 end of a movement. But for at least 6-7 times I found a mistake, fixed,
     33 my code would solve the example case correctly but my answer on the real
     34 input was wrong. At some point I started rewriting the code in alternative
     35 ways hoping to get a different answer, and one of those versions worked.
     36 Still no idea why.
     37 
     38 So in the end it took me more than 40 minutes to solve part 2. Great start!
     39 
     40 ### Day 1: Secret Entrance
     41 
     42 I misread the statement for part 1 and I accidentally solved part 2 first.
     43 I re-read the problem description, fixed my code, submitted it, and then
     44 I just had to press `Ctrl+Z` (actually `u` on vi...) enough times to solve
     45 part 2.
     46 
     47 ### Day 3: Lobby
     48 
     49 My solution for part 1 is ad-hoc and not very good. I should have thought
     50 about it a bit longer, the general solution isn't much harder to find.
     51 
     52 For part 2 I used recursion with memorization (using Python's
     53 `functools.cache`), which is fast enough. But later Chiara pointed
     54 out to me that actually the solution is quite trivially greedy; I
     55 implemented the greedy version in `b-alt.py`.
     56 
     57 ### Day 4: Printing Department
     58 
     59 The first "map" problem of the year! This one was easy, but I
     60 made a lot of mistakes in part 1. I decided to use the trick that
     61 [Jared](https://guissmo.com) suggested a couple of years ago: extend the
     62 map by 1 cell in all directions so you don't have to deal with indices
     63 out of bounds.
     64 
     65 For part 2 I decided to quickly code the dumb "repeat part 1 until no
     66 rolls are removed" strategy and it worked.
     67 
     68 ### Day 5: Cafeteria
     69 
     70 Part 2 required a little bit of thinking to handle overlaps correctly
     71 - at first I wrote a solution that did not handle overlaps, then one
     72 that can only handle single overlaps, and finally one that works in
     73 every case. My final solution is quite straightforward.
     74 
     75 ### Day 6: Trash Compactor
     76 
     77 Part 1 was easy, but I struggled with part 2.
     78 
     79 I had to solve this while travelling, which did not help, but that was
     80 not the main issue. The problem was that for whatever reason my script
     81 did not copy the whitespaces correctly from the sample input in the web
     82 page, so I was left wondering how the heck am I supposed to align the
     83 numbers. After more than an hour and after changing train, I figured out
     84 the error and I was able to solve this elementary school problem. Much
     85 smart, very accomplishment.
     86 
     87 This year so far the only problems that took me more than 30 minutes
     88 are this and the first one, not exactly the hardest problems imaginable.
     89 
     90 ### Day 7: Laboratories
     91 
     92 This was quite fun! For part 1, I iterate over the rows of the diagram
     93 keeping a list of the position currently occupied by a tachyon. I use a
     94 Python set to avoid duplicates. Part 2 is very similar, but the set is
     95 changed to a map where the keys are the positions and the values are the
     96 number of multiverses where a tachyon is in that position.  To update
     97 this value for the current row, I sum the values of all tachyons that
     98 end there from the previous row (that can be one or two tachyons).