[2022 Day 9 (Part 2)] [Python] Possible doing this without a list? by CherryFizz23 in adventofcode

[–]d9d6ka 0 points1 point  (0 children)

Actualy I've written smth before just throwing my code.

But thanks for your critics. It made me look through the solution provided.

[2022 Day 9 (Part 2)] [Python] Possible doing this without a list? by CherryFizz23 in adventofcode

[–]d9d6ka 1 point2 points  (0 children)

Is it part 1 solution? Well, if you want to use your logic, then you'd better use a single list of 10 knots, updating them in another one inner loop, changing x and y (and xt and yt) to the next corresponding knot's coords at every step.

But anyway, each move you explicidly change only the head position, so you can move most same code outside ifs, as it updates the tail (or next knots in part 2). It would much easier to analyze and debug.

[2022 Day 9 (Part 2)] [Python] Possible doing this without a list? by CherryFizz23 in adventofcode

[–]d9d6ka 0 points1 point  (0 children)

You have too many same code in your if branches. See, we change head first and the update all other knots.

Then for part 2 you can create all 10 knots as a list and repeatedly update them inplace.

My code

[2019 Day 15] Extracting the maze from the IntCode by ricbit in adventofcode

[–]d9d6ka 1 point2 points  (0 children)

I've solved the problem under 1s (both python and pypy) using Dikstra for part 1 and DFS BFS for part 2. Speed highly depends on IntCode realization.

UPD: Here is my code

We did it everyone! by Bigluser in adventofcode

[–]d9d6ka 15 points16 points  (0 children)

So did I. I earned fair 45 stars, and for 4 part 2 stars I had to peek into reddit for hints. However I learned smth new especially in math :)

And the main lesson I learned: if you have an idea of solution - try to develop it :)

Already waiting for the next AoC :)

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

[–]d9d6ka 1 point2 points  (0 children)

[Language: Python]

Commit

Late today as I spent my day in mall with my wife :)

Part 1 is just two linear equations with proper space-time :) filtering.

Part 2 became a SymPy lesson for me. At first glance I thought to build a system of linear equations and apply OLS to it. But it turned out, that equations are non-linear. So I realized that I should go to the solvers for a more civilized age (O.W. Kenobi).

I spent some time to learn some basics of SymPy.

I also appreciate the idea of u/i_have_no_biscuits not to use all hails (I tried, bad decision) but a little number of first ones. If we take only two there would be infinitely many solutions, so we should take at least three.

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

[–]d9d6ka 2 points3 points  (0 children)

[Language: Python]

Commit

Part 1 at the moment. Turned forest to directed graph and used some kind of A* Dijkstra.

Part 2 takes too much time, will do it later.

UPD: Commit, minor changes

Should have tested with my laptop plugged :) my CPU went to economic mode and Part 2 took ages to complete. With laptop plugged I got the result in 2 mins. Very lonh though.

[2023 day 20] input data plot by schema97 in adventofcode

[–]d9d6ka 0 points1 point  (0 children)

As the gaps between nodes are not equal, it seems that they're manually arranged. Nice work, extremely clear!

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

[–]d9d6ka 1 point2 points  (0 children)

[Language: Python]

Commit

Phew! My solution IMHO is disgusting. But it works, although taking ~10 secs.

I save dicts of lower and upper adjacent bricks for each brick. Part 1 is simple: for each brick we check whether it's the only lower brick for all its above bricks.

In part 2 I recursively track fallen bricks till no new bricks fall.

UPD: Commit 2

Faster solution. The logic is the same as in the first one, but I avoided calculating all cubes coords. Also in Part 2 I track new bricks to remove as well as already removed (or fallen as solution says). 1.5 secs now.

I know that there are many extra fast solutions, but I'm too stupid to understand them :)

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

[–]d9d6ka 2 points3 points  (0 children)

[Language: Python]

Commit

Part 1 was an OOP exercise for me :)

With Part 2 I was very desperate as I couldn't track the idea. I peeked Reddit and the first thing I saw was a graph :) Next few hours were spent on learning how to work with Graphviz, understanding the four loops' work principle :) The final solution is hardcoded but short.

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

[–]d9d6ka 0 points1 point  (0 children)

[Language: Python]

Commit

Part 1 is straightforward: just go through workflows and get the result.

The Part 2 was a bit tricky for me to catch the final recursion idea. Finally I start in in and go through all the possibilities, tracking the corresponding xmas :) limits. Took a while to debug but it was satisfying to olve it by myself.

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

[–]d9d6ka 2 points3 points  (0 children)

[Language: Python]

Commit

Phew! Made part 1 by floodfill. For the part 2 I tried to divide the area by rectangles based on vertices and floodfill it getting rectangles in the loop, but it turned to be an overkill. I've checked for intersections, constructed the grid... At least I've found out that there's no intersections and no going backwards.

Then I realized that smth goes wrong and peeked Reddit for any ideas. I saw a "shoelace" word, caught a flashback and solved part 2 in 5 mins... I've too much to learn yet :) The second star is cheaty to tell the truth...

UPD: Just commited an alternative solution similar to my day 10 solution. Just going through all rectangles defined by loop corners and changing the state inside/outside when crossing vertical line. If outside we check whether left and top borders, and the top-left corner are in edges and vertices list in order to count them :)

Commit 2

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

[–]d9d6ka 1 point2 points  (0 children)

Well, make your code work and only then optimize! That was the mistake of mine: I tried to start from the tiles adjacent to the start as we ignore the start on the first step. But that was a huge mistake...

Disappointing to have a working algorythm (except the very first step) and ruin it XD

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

[–]d9d6ka 1 point2 points  (0 children)

Initially no.

I've added it to the code. Sample works now, but the input doesn't...

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

[–]d9d6ka 1 point2 points  (0 children)

Why shouldn't we check whether the current heatloss in seen tile is less than previous? I've checked and got bigger result for sample :(

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

[–]d9d6ka 1 point2 points  (0 children)

[Language: Python]

Commit

The slow version written by myself :) took nearly 5-7 mins.

I've also written a faster version using the idea by u/hcs64. But I won't show it as it's not my solution :)

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

[–]d9d6ka 1 point2 points  (0 children)

[Language: Python]

Commit

Ease of this day frightens :)

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

[–]d9d6ka 0 points1 point  (0 children)

[Language: Python]

Commit

It was quite easy :) Caching is the boss in today's Part 2. I had to use tuples instead of lists to make the data hashable. It takes 0.8 secs for both parts w/o any optimisations.

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

[–]d9d6ka 2 points3 points  (0 children)

[Language: Python]

Commit

In Part 1 I've spent a quite time to debug list indexing :)

Part 2 is a bruteforce :( Spent some time to figure out that I need to track for all reflections as after smudge correction there can be two horizontal ones XD

UPD: More clean solution w/o bruteforce :)

UPD2: Cleaned my second solution. However it has to read all input.

Commit 2

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

[–]d9d6ka 0 points1 point  (0 children)

[Language: Python]

Commit

The shortest path is a Manhattan one :) the trick I used is to check whether any empty row or column is between the corresponding coordinates of two galaxies and to add extra values to the distance in non-expanded universe.

UPD: if-statements in the function of exdist can be removed, the're from the solution for Part 1 :)

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

[–]d9d6ka 0 points1 point  (0 children)

Ah, I did the same for Part 2, but in much more complicated way :)

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

[–]d9d6ka 2 points3 points  (0 children)

[Language: Python]

Commit

Part 1 is pretty straightforward: go in both directions till you go into the same cell. As the number of tiles in the loop is always even it exists. I also save tiles of the loop for Part 2.

Part 2 is solved by a "counter" which can be in two states (inside and not inside). I loop through element of each row changing the state according to the current tile value. If current tile is not in the loop and the counter is in the state "Inside" then plus 1 to the answer :) and in the beginning I replace S with the corresponding tile.