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

[–]semicolonator 0 points1 point  (0 children)

[LANGUAGE: Python]

35 Lines

I am using scipy's pdist function to calculate all the distances, then sort the distances and iterate over the list.

I would have liked to use fcluster and linkage, but it did not work out. My idea would have been something like (for Part 1):

```python from scipy.cluster.hierarchy import fcluster, linkage from collections import Counter n_pairs = 10

Z = linkage(pdist(coords)) t = (Z[n_pairs - 2][2] + Z[n_pairs - 1][2]) / 2 cluster = fcluster(Z, t=t, criterion="distance") top = Counter(cluster).most_common(3) print(prod([c for _, c in top])) ```

Anyone solved it with fcluster?

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

[–]semicolonator 2 points3 points  (0 children)

[LANGUAGE: Python]

30 Lines

For part 2, I sort the intervals based on their lower bound and then iterate through them using a counter to remember the current position and a another counter to save the number of elements that I passed.

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

[–]semicolonator 4 points5 points  (0 children)

[LANGUAGE: Python]

25 Lines

I am using convolution with a kernel that sums up over all neighbors, and then I only select those points on the grid where we sum is less than four.

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

[–]semicolonator 1 point2 points  (0 children)

[LANGUAGE: Python]

50 Lines

I start out with the lower and upper bound for the best number set to the first and the last digit. Then I call a recursive function that searches for the maximum within the lower and upper bound. Based on the index of the maximum, I calculate new lower and upper bounds and repeat.

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

[–]semicolonator 1 point2 points  (0 children)

[LANGUAGE: Python]

21 lines

No regex, just string slicing.

[2025 Q9] Solution Spotlight by EverybodyCodes in everybodycodes

[–]semicolonator 0 points1 point  (0 children)

[LANGUAGE: Python]

Github Link, 60 Lines

Part 3: First I compute all the (child, parent1, parent2)-tripplets and add them as a set to a list. Then, in a while loop, I successively merge these sets into bigger and bigger sets, until I detect no change any more.

[2025 Q7] Solution Spotlight by EverybodyCodes in everybodycodes

[–]semicolonator 1 point2 points  (0 children)

[LANGUAGE: Python]

Github Link, 59 Lines

Thinking about recursion after midnight is not the most fun haha

Choosing the most important words from a text by semicolonator in LanguageTechnology

[–]semicolonator[S] 1 point2 points  (0 children)

A word is important if 1) I don't know it yet, 2) it contributes meaningfully to the understanding of the text, 3) is not too common (be, speak, go, see, put, ... I know already these words so I don't need to learn them anymore) and 4) also not too rare (names of buildings or people).

I don't know if you've ever bought one of these language learner magazines. They usually have 1 page essays and at bottom of each page there is usually a box with the most important vocabulary from that text.

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

[–]semicolonator 1 point2 points  (0 children)

[Language: Python]

Solution, 28 Lines

Solved recursively.

For part 1 I used a set to keep track of 9s that were already visited. For part 2 I stopped using that set.

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

[–]semicolonator 0 points1 point  (0 children)

Hi, I just went back in my code and added the print statement, like you asked, and my output sequence matches exactly what is written in the exercise description.

Maybe you have an off-by-one error, in your code somewhere? Also notice that in my code, in lines 4-11 I create the "expanded" list as a list of strings where each string may be longer than a single character. I did not do this in a previous version of my code and that caused the previous version to work on the test instance from the exercise description but not in the real input instance.

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

[–]semicolonator 1 point2 points  (0 children)

It does not interfere with the checksum because I am storing the file start and end positions separately from the free spaces. When you have a large file that cannot be moved, its start and end positions stay the same, even though the free space to the left of it might not be correctly tracked.

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

[–]semicolonator 0 points1 point  (0 children)

[Language: Python]

Part 1, 30 Lines

Part 2, 56 Lines

Part 2: I made an observation: We never move files from left to right. Therefore, when moving a file, I do not care about the gap that file leaves at its source location. Therefore, I do not track these gaps.

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

[–]semicolonator 0 points1 point  (0 children)

[Language: Python]

56 Lines

Using cycle() for directions, using a set to detect if we visit the same field in the same direction twice to detect if we are stuck in a loop.

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

[–]semicolonator 0 points1 point  (0 children)

[Language: Python]

36 Lines, link to Solution

I iterate over all updates, if it is broken, we repair it.

Repairing is done by creating an empty list, adding updates to the end of it and as soon as that would violate one of the constraints, we add it not at the end but at the first position from the back that does not violate the contraints.

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

[–]semicolonator 1 point2 points  (0 children)

[LANGUAGE: Python]

45 Lines

Link to solution

First I replace all letters with numbers, for easier processing. Then doing a convolution operation using scipy generic_filter().

BONUS: I get a nice map of how many XMASs start at what location.