This repository contains my solutions in Python for the puzzles of Advent of Code 2023.
Until day 19, I was on track. Then, the real family holydays started. Now, I am trying to close in missing puzzles during spare time.
Please, contact me if you have any comments or suggestions for the proposed solutions.
- Dávid Németh publish nice C# solutions.
- Daria Vasyukova has pretty clean Python solutions with very beatiful animations, implemented using PyGame.
- Pietroppeter is publishing solutions in NIM and Gleam
- Hakank is publishing solutions in Picat and SWI-Prolog (... old good Prolog!).
- Peter Norvig has a complete collection of solutions for past editions, among other PyTudes.
-
Day 25 Still missing...
-
Day 24 Still missing...
-
Day 23 Still missing...
-
Day 22 Still missing...
-
Day 21 Part 1 is easy, while Part 2 was a real challenge. The intution of using polynomial fitting of degree 2 (a parabola) came straight, but filling in the details, was hard. Still, I have learned using np.polyfit (for my first attempt, I made a manual fitting looking at my grid plots).
- REMARK: Strange enough,
wc -l input
was counting 130 rows instead of 131, and this made me crazy. Fixed after reading this post.
- REMARK: Strange enough,
-
Day 20 Still missing...
-
Day 19.part 1 Working on solving part 2 (part 1 was easy).
-
Day 18 Once you realize that the puzzle is about computing the area of a closed simple polygon, than you can implement the corresponding closed formula, a particular type of Shoelace formula.
-
Day 17 Best puzzle so far! Solved using A* (a-star) search algorithm with a heap priority queue.
-
Day 16 Easy puzzle, but it was the occasion to play with namedtuple.
-
Day 15 Finally, an easy puzzle.
-
Day 14 This time I implemented my own memoization over a numpy matrix using the builtin hash as suggested in a comment here.
-
Day 13 The puzzle was hard not because of coding, but because it was hard to understand the assignment. Solved with numpy matrices, not_equal, and zip.
-
Day 12 This one was hard, until I realized that using tuples (read only) instead of lists (unhashable) as input arguments to function enables the decorator @cache, which implements lightweight memoization. For differences between @cache and @lru_cache, read this post.
-
Day 11 Easy, with numpy matrices. Nothing to declare, but it nice to plot the galaxies with imshow.
-
Day 10 It's hard to work on Sunday, but Part 2 was completed on Monday.
-
Day 9 Nothing to declare. That's fine, since it is Saturday after all!
-
Day 8 Almost as hard as Day 5, but this time brute force didn't work at all. I need to draw a directed graph, detect cycles, and then to reason in term of period and least commom multiple.
- REMARK: From Python 3.9+, there exists the builtin lcm, for computing least common multiple.
-
Day 7 A classic puzzle! A poker-like card game, with a custom order for handling jokers. Easy, no remarks.
-
Day 5 BIS: This time I used a disciplined approach: first, draw on a blackboard; second, code with intervals and recursioins. Going down from an hour of runtime to 0.001 seconds is quite rewarding. And I didn't need numpy at all. Here the second solution: fertilizer_v2.py
-
Day 6 Nice application of quadratic equations. This time, speding some minutes with paper and pecil before coding was very productive... and I got the best rank of these first 6 days.
-
Day 5 Hard job this time. The puzzle logic was easy, but to find an efficient solution was the real challenge. Using numpy array with np.where test, I was able to solve the puzzle in less than an hour, but it is defintely too long.
- Remark: next time, think more befor coding. I should revisit this puzzle!
-
Day 4 Today, for parsing cards, I use set which checks membership in O(1) average case. Second part was cute, but not very hard.
- Remark: for a review of the time complexity of Python builtin, see wiki.python.
-
Day 3 I have admit that with a family is harder to work on AoC puzzles on Sunday. This is an ugly (unelegant) solution, but still, it works. Python dictionaries are always there the simplify the second part of the puzzle. Remark:
- Remark: Today, I learned about numpy.char.array, which are better than numpy.matrix of string.
-
Day 2 Easy with dictionaries, both first and second part. Implemented in functional syle (with
map
,reduce
, andsum
). -
Day 1 The first part was easy, the second harder (I failed twice). It was unclear whether the string
'eightwo'
should be converted into 88 or 82 (and it was the second).- Remark: I learned how to reverse a string with slicing.