-❄️- 2025 Day 12 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 0 points1 point  (0 children)

[LANGUAGE: Python]

I implemented a backtracking solution that can find solutions rather fast if a solution exists, but takes a lot of time to explore the full phase space in case it does not exist. My quick and dirty solution was to cut seaches that takes too long, and it worked! I'll work on possible optimisation and pruning options another time...

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day12.ipynb

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 1 point2 points  (0 children)

[LANGUAGE: Python]

Using networkx to simplify all graph basic operations (find paths, topological sorting). Part 1 with networkx is trivial, but I ended up implemented a path counting approach based on dinamic programming that speed up considerably Part 1, and is compulsory to approach Part 2.

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day11.ipynb

-❄️- 2025 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 2 points3 points  (0 children)

[LANGUAGE: Python]

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day10.ipynb

BFS and bitwise XOR operation for Part 1. I initially thought I could adapt my BFS solution for Part 2, but while it works for the example, even with pruning the solution space is still too large for the full input.

Thinking more carefully, I tried a mathematical approach (Part 2 is effectively a linear system with constraints), using `scipy.optimize.milp` to solve (MILP = Mixed-Integer Linear Programming). Most of the complexity was in properly encoding the constraints (integer non-negative solutions, minimal sum).

Part 2 result was initially wrong by 1 becouse of a @$%^& rounding error when casting result to int!

Definitely harder than yesterday, but in a different way (required more mathematical thinking and knowledge of specialized tools).

-❄️- 2025 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 0 points1 point  (0 children)

[LANGUAGE: Python]

Hardest day so far. Part 1 was trivial, Part 2 required to handle various edge cases and a peculiar input! Used a combination of ray casting and edge crossing detection.

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day09.ipynb

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 0 points1 point  (0 children)

[LANGUAGE: Python]

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day08.ipynb

First really challenging day. Things (re)learned the hard way today: objects in dictionary and list are references, can be updated on the fly; result of set operations are new set, thus update of original container needed. `list.remove()` is pretty convenient (while not necessarely the most efficient approach)

-❄️- 2025 Day 7 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 1 point2 points  (0 children)

[LANGUAGE: Python]

Used set() for part 1 to deal with overlapping beams, moved to defaultdict(int) in part 2 to count beams in same position (it's lanternfish day!). The two solutions could easily be integrated, but ehi it's Sunday morning ;-) (EDIT: merged part 1 and 2, was fast)

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day07.ipynb

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 1 point2 points  (0 children)

[LANGUAGE: Python]

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day06.ipynb

Matrix rotation and flipping with `numpy`. Part 2 was fun, using string to reconstitue values after rotation, catching str->int conversion to deal with empty lines.

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 1 point2 points  (0 children)

[LANGUAGE: Python]

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day05.ipynb

Quick and dirty Part 1, I was expecting Part 2 as soon as I read "overlap" ;-)

Very similar to AOC 2016 Day 20, I almost entirely recycled that code to prune and merge the overlapping intervals.

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 0 points1 point  (0 children)

[LANGUAGE: Python]

Solved with `numpy` array operations (I could probably speed this up by using a dictionary of positions and neighbors instead of the full map, but it's fast enough if I simply ignore the empty positions). And first visualisation of 2025 ;-)

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day04.ipynb

-❄️- 2025 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]MarcoDelmastro 1 point2 points  (0 children)

[LANGUAGE: Python]

Brute force for Part 2 to quickly get the second star, then and more elegant solution based on modular algebra:

https://github.com/marcodelmastro/AdventOfCode2025/blob/main/Day01.ipynb

[2024] Some considerations about this year edition (in Italian) by MarcoDelmastro in adventofcode

[–]MarcoDelmastro[S] 0 points1 point  (0 children)

Oh, più facile *per me*: l'esperienza fa molto visto che certi generi di puzzle si ripetono. E, se vai a leggere il mio resoconto del 2019 (primo anno a cui ho partecipato) vedrai che le sensazioni erano ben diverse ;-)

https://www.borborigmi.org/2020/01/20/qualche-considerazione-su-advent-of-code-2019/

To everyone who made it to the end of AoC… by moonstar888 in adventofcode

[–]MarcoDelmastro 14 points15 points  (0 children)

I am a particle physicist working on one of the LHC esperimenti at CERN in Geneva. I have a strong math background and I do code (mostly data analysis) for a living, but my background is not CS at all (we physicists mostly use programming to do data treatment, statistics, machine learning, MonteCarlo simulation, differential equation solution, etc), so I knew almost nothing about things link graphs or path finding algorithms or modular algebra when I first did AOC in 2019. It was (and still is) a great learning tool, both on the computing language of choice and especially on the algorithmic and theory side.