stegua / AVC2023

My Python solutions for Advent of Code 2023

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Python AdVent of Code - PyAVC 2023

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.

Other solutions and/or programming languages

Personal commments

  • 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.
  • 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.

    • REMARK: Plotting matrices with imshow helps in getting insights for inside and outside galaxies.
  • 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.

  • 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:

  • Day 2 Easy with dictionaries, both first and second part. Implemented in functional syle (with map, reduce, and sum).

  • 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.

About

My Python solutions for Advent of Code 2023

License:MIT License


Languages

Language:Python 100.0%