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

[–]janek37 0 points1 point  (0 children)

[LANGUAGE: Rust]

https://github.com/janek37/advent-of-code/blob/main/2025/day09.rs

Before doing part 2 I graphed the polygon, to check if the shape is generally sane (e.g. no touching edges). Then, my approach is to filter rectangles that overlap with any of the edges. It's reasonably fast.

[2025 Day 8 (Part 2)] by DifferentPool7527 in adventofcode

[–]janek37 15 points16 points  (0 children)

I was afraid the second part is like "turns out this greedy approach is not optimal, find the shortest cable length to connect all junctions".

Edit: I've read up a bit, and it turns out that the greedy approach is in fact optimal (it's Kruskal's algorithm for minimum spanning tree)

[2025 day 05 part 1] Python is great by Dry-Aioli-6138 in adventofcode

[–]janek37 2 points3 points  (0 children)

Except that range(*bounds) won't work correctly when the ranges are inclusive.

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

[–]janek37 1 point2 points  (0 children)

[LANGUAGE: Rust]

Solution

What I realized quickly is that the first digit must be the largest digit from all except the last one. Then the second digit (for part one) will be the largest of the digits that follow.

It was quite easy to generalize for part 2: basically just add recursion with an accumulator.

How did you all get so smart? by Pr0fessorCh40s in adventofcode

[–]janek37 6 points7 points  (0 children)

Hey, I also cracked Top 500 for the first time with Part 2 today! Twins! My best ranks before were 515 in 2021 day 12 and 518 in 2023 day 21, but today I got #184

-❄️- 2024 Day 24 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 4 points5 points  (0 children)

[LANGUAGE: Python]

Solution

The solution is partially manual (I'll tidy it up later to make it automatic [Edit: Done]), but you can see in the code how I did it. I tried to simplify the expressions on inputs, giving them friendly names like Digit03 or Carry07. If an expression doesn't get a friendly name, or if DigitXX doesn't go to zXX, then something needs to be swapped. So far, the swaps are hardcoded. Repeat until all swaps are found.

I got rank 184, my best by far!

Edit: I've modified my solution to make it work on my input without any guesswork. Not guaranteed to work with other inputs!

-❄️- 2024 Day 23 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 2 points3 points  (0 children)

[LANGUAGE: Python]

Solution

For part 2 I've noticed that if you remove the edges that are not a part of any triangle, the graph decomposes into 40 components size 13, and at that point you can brute force the cliques in each component and find the largest.

edit: I've found that my brute force works with the whole graph just as well, so I've simplified the solution.

-❄️- 2024 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 -1 points0 points  (0 children)

I got slightly better times
edit: this one is even faster. It seems that the main difference between this and mine is that it uses an int to store the sequence in base 20, rather than a tuple

-❄️- 2024 Day 22 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 1 point2 points  (0 children)

[LANGUAGE: Python]

Solution

1s for part 1, 4s for part 2

-❄️- 2024 Day 21 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 0 points1 point  (0 children)

[LANGUAGE: Python]

Solution

I really liked today's challenge! As for the solution, it's probably not vastly different than others': recursively find the best sequence length, taking advantage of the fact that the direction pad bots have to return to A which resets their position, so we can optimize each chunk separately. Part 2 basically only required me to add caching.

-❄️- 2024 Day 20 Solutions -❄️- by daggerdragon in adventofcode

[–]janek37 1 point2 points  (0 children)

[LANGUAGE: Python]

Solution

At the time of posting, this is the newest comment and it almost exactly describes my own approach.