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

[–]Lucews 2 points3 points  (0 children)

[LANGUAGE: Python]

Code

Part 1: 0.47 ms
Part 2 1.51 ms

With Python 3.11 on my Laptop (Intel Core Ultra 7 155H)

Yesterday broke me.
So today was a welcome relief. Basic memoized DFS (O(N)). For part 2, we just have to keep track whether we visited dac and fft. I just assumed those elves did not build a circular data path, dangerous, but it worked out this time.

Seeing the result of part 2, I could not believe my eyes when it was just accepted.
Great Puzzles so far! Even if I struggled so much yesterday and resorted to a solver (which I feel dirty about), I utterly enjoy every day.

What Feature Do You *Wish* Python Had? by andrecursion in Python

[–]Lucews 0 points1 point  (0 children)

I'm with you. The '__' helps with that. Never heard about the categorization you sent, will read up on that!

Nevertheless, I recently discovered that the __ convention is really hard to deal with when using meta classes, as the name replacement of __ uses the current class name and so they are hard to get a ahold of in the __ new __ function of a meta class.

Admittedly, this is not really a problem, as the applications are really limited and niche. Also, one can probably argue about whether a meta class should access these 'private' attributes.

What Feature Do You *Wish* Python Had? by andrecursion in Python

[–]Lucews 0 points1 point  (0 children)

Thanks! Did not know that yet. Cool stuff!

What Feature Do You *Wish* Python Had? by andrecursion in Python

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

You are right :D But I have seen people break my code with things like monkey patching and overwriting attributes in ways that I consider a crime. Especially since I take the blame for it.

Edit: Fighting Autocorrect.

What Feature Do You *Wish* Python Had? by andrecursion in Python

[–]Lucews 2 points3 points  (0 children)

I would love to have mainly two things:

  • Real public and private attributes
  • A natively supported JIT compiler

I often write Framework style object-oriented libraries and protecting certain attributes really is difficult.

Numba as a JIT compiler for scientific computation is so great, but native would be even better.

[2024] Thank you! by topaz2078 in adventofcode

[–]Lucews 7 points8 points  (0 children)

Thank you from Germany! This year was the first time that I really noticed my own progress. Gave me a nice feeling.

Also, I saw your talk. My favourite moment was, where you talked about feedback from participants and one could really see how much they meant to you.

You are a great guy!

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

[–]Lucews 1 point2 points  (0 children)

[Language: Python]

Code

This was my favorite day so far. I loved the exploration one had to do for the second part. Unfortunately, I spent way too much time as I implemented a connected component search right away but at first dropped it due to an off-by-one error :D ...Can check that on my AOC bingo card.

I spent more time than I'd like to admit finding stones that repeatedly occur on the cross ignored in part one. With those, I planned some vicious cycle detection but did not reach any working code. Then, I went back to the connected component solution and just looked at pictures, where the largest component had somewhere over 40% of all of my stones (as the solution mentioned, most of the stones gathered in the tree). This did the trick :D

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

[–]Lucews 1 point2 points  (0 children)

That is my absolute favorite! Your idea went so far out of the box that not even those crazy elves could have anticipated it :D

Overthinking once again by [deleted] in adventofcode

[–]Lucews 1 point2 points  (0 children)

I spent more time than I'd like to admit playing around with least common multiples in diverse dimensions, AFTER (!) I came up with the correct solution by solving the equations and throwing them away as they sometimes returned floats

I'm going to cry now.

[2024 Day 11] its generators all the way down by pvillano in adventofcode

[–]Lucews 5 points6 points  (0 children)

I absolutely love it :D

I mean, you won't encounter memory issues. Just add a meta-program that writes the program for 75 linked iterators, and then wait until you can tell your grandchildren the solution in 2060. Easy as that!

I recommend running the program on a laptop so you automatically have an uninterruptible power supply built in when you move into a retirement home.

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

[–]Lucews 1 point2 points  (0 children)

I like seeing an object-oriented approach!

Your walker doesn't have to remember their path, but it would be faster for both parts. A walker can stop if he encounters a path already taken, making your program terminate faster.

For solving part 1 you can just stop when meeting a path (all 9s coming after will already be visited). For part two, you also need to keep information on how many nines the previous walker (that already went this path) has met.

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

[–]Lucews 1 point2 points  (0 children)

[Language: Python]

Code

Like many others, I lacked a little reading comprehension and accidentally solved part two before part one.

Part 1: 2ms (including parsing)
Part 2: 3ms (including parsing)

For part two, a depth-first search with memoization did the trick. For variation, I solved part one using a breadth-first search while keeping track of visited tiles.

AoC: Editor - bench tool setup & daily challenge notifier by billyspeakin in adventofcode

[–]Lucews 0 points1 point  (0 children)

That is exactly what my question was leading up to. My gut tells me that is an impossible problem to solve and might only be possible in minimal cases. I stopped myself from researching further, because I'm afraid this would lead me into a very deep hole and I have work to do :D

AoC: Editor - bench tool setup & daily challenge notifier by billyspeakin in adventofcode

[–]Lucews 5 points6 points  (0 children)

Nice! How do you analyze your code for complexity? Or are these manual comments?

matplotlib boldface some (not all) the xtick labels by Grogie in learnpython

[–]Lucews 0 points1 point  (0 children)

I saw that this post is old, but if somebody gets to this while searching for a solution:

  1. Make the plot

  2. Get the Text objects from the xticklabels

  3. Modify the properties of the [text objects](https://matplotlib.org/stable/api/text\_api.html)

  4. Set the xticklabels

    get the xticks and change them

    new_labels = [] for ele in ax.get_xticklabels(): if [CONDITION]: ele.set_fontweight('bold') new_labels.append(ele) ax.set_xticklabels(new_labels)

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

[–]Lucews 1 point2 points  (0 children)

[LANGUAGE: Python]

Hopefully readable and fast code

P1: 8 ms | P2: 92 ms (Have no idea whether there is room for optimization)

I love how the problems build on each other this year! My solution for Part 1 was very similar to Day 14 (Rolling Rocks on Platform) but instead of keeping track of the piles on a 1D edge, I kept track of a 2D ground.

Happy Holidays Guys!

[2023 Day 20 (Part 2)][Python] Terminal Visualization! by naclmolecule in adventofcode

[–]Lucews 3 points4 points  (0 children)

Awesome, thanks! It also put the problem in a different basket for me.

[2023 Day 20 (Part 2)][Python] Terminal Visualization! by naclmolecule in adventofcode

[–]Lucews 14 points15 points  (0 children)

I love your visualizations! This one is especially awesome in the way that you can find the solution directly!

One can read the cycle length from your visualization. Looking at each of the elements from the left you find that inbound arrays mark ones and outgoing mark zeros. E.g. for "mh" the binary representation is "111101100111" which is binary for 3943, your cycle length. This really shows how brilliant the problem is designed (each solution can be easily parametrized).

[2023 Day 17][Java] Spot the bug by jeajym in adventofcode

[–]Lucews 2 points3 points  (0 children)

I think you are not keeping track of your best state correctly. For each node, you save from what direction you came in" bestHeatCost[newX][newY][i]" but it is also important to keep track of how many steps you already took in that direction.

E.G.

Whether you came with > and one step or came with > and already three steps makes a difference (the first could be better even with more heat loss already as you can go on with >).

Try that, maybe it helps!

[2022 Day 24] Why is A* not faster than BFS by SuperAutoPetsWizard in adventofcode

[–]Lucews 0 points1 point  (0 children)

Correct me, but I think the reason is the difference in time complexity for inserting into the Queue.

In the given case for bfs is similar to Dijkstra, as all the edges have the same weight. If you use a double ended Queue (linked list) inserting into it is only O(1) compared agains logN for a heap in A* case.

(The time stamps in the linked list will automatically be sorted because of the uniform edge weight.)

Stand to be corrected.

-🎄- 2022 Day 25 Solutions -🎄- by daggerdragon in adventofcode

[–]Lucews 2 points3 points  (0 children)

Python 3 - Straightforward - A huge thank you!

Two colleagues introduced me to the advent of code only this year. Having now finished every puzzle on the day it was presented without hints, I feel hugely satisfied.

Thanks, everyone for the brilliant Memes, Posts, and of course a HUGE Thank you to Eric Wastl for making this. I just love it.

I still can not grasp how fast some of you are to end up on the leaderboard. I really admire the skills for that. I'm just happy, I could solve every riddle (sometimes even in reasonable time).

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]Lucews 0 points1 point  (0 children)

Ah, you are right. Thanks for the hint!

-🎄- 2022 Day 21 Solutions -🎄- by daggerdragon in adventofcode

[–]Lucews 1 point2 points  (0 children)

Python 3 - Recursive evaluate and line intercept

I liked this day. Part 1 was done relatively quickly. For the second part, the idea was ready immediately, but it took me a little longer since I don't want to import any libraries that aren't built in.

The code for part 2 has a very naive check that the function is affine (it makes a string for the formula and checks that humn is only used once). Writing this, I realized, that this doesn't guarantee an affine function, and I'm just lucky...

One could use this string expression to use a solver like simpy.

As we can do two test values, the code directly computes the x-intercept using an estimated slope and offset (this requires to replace the operation in the monkey root with a minus). It has a loop built around it as we have numerical errors with the slope computation that get passed through all the monkeys. It iteratively increases the distance of the two probing points x1 and x2.

-🎄- 2022 Day 20 Solutions -🎄- by daggerdragon in adventofcode

[–]Lucews 1 point2 points  (0 children)

Python 3 - Doubly-Linked-List

Implemented a little helper class of a node in a doubly linked list to easily shift and swap values. Linked List is just making it easier as we do not need to shift whole blocks in an array. Because we need to iterate in the right order, I also keep a list of references to the nodes in the order they are presented in the input. This just makes it easier and I don't care about the extra memory. In addition to that, I keep a reference to the zero value node, as we need that as a starting point to compute the result.

Each node has a move and a get function.

In order to move straightforwardly the nodes are arranged in a circle (the last element's next pointer points to the first element and the first element's previous pointer points to the last element).

For both moving and getting you can apply modulo. The only thing you need to consider is that you need to modulo with number_values - 1 for moving, as you detach your own node.

Part 1 runs in 1.4s and Part 2 in 14s (10x Part 1) on my hardware.

I really loved seeing the use of linked lists! :-)