2025-advent-of-code

following along with the advent of code 2025 (Matlab)

View on GitHub

Day 07

Beamsplitting problem …

.......S.......
...............
.......^.......
...............
......^.^......
...............
.....^.^.^.....
...............
....^.^...^....
...............
...^.^...^.^...
...............
..^...^.....^..
...............
.^.^.^.^.^...^.
...............
...|...
...^... 

Tips for first problem

  1. Parse the input into a matrix of characters.
  2. Find the source position S. Finde the positions of all splitters ^.
  3. Create a function that simulates the beam travel - row by row, starting from the source position.

  4. For each row, check if the beam is above a splitter. If so, split the beam into two beams at i +/- 1.

Second problem

… requires a bit more algorithmic thinking. This is a kind of pathfinding problem, where we need to explore all possible paths the beam can take through the grid. I never had time to learn details about dynamic programming which is one of the ways to solve such problems efficiently. And I couldn’t find a brute-force way to even try within the day… so I ended up asking chatGPT for help (!) - so the solution for B is actually pretty much entirely written by chatGPT, with some minor modifications by myself.

Day 7 diagram

Code

Julia solution

Julia code / solution for the first part of that problem (simpler version of the code ended up as solution for B!).

Second part solution of that problem (NB! The actual pathfinding function was written by ChatGPT. Kind of mad - but it worked straight out of the box).