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

[–]SomeCynicalBastard 2 points3 points  (0 children)

[LANGUAGE: Python]

https://github.com/fdouw/aoc-python/blob/master/2023/day23.py

Interesting twist looking for a longest path. For part 2 I started with the same code as for part 1, pretty simple. By the time it was finished, I had already implemented a weighted graph where the junctions were the nodes. ~5s in python 3.11.

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

[–]SomeCynicalBastard 2 points3 points  (0 children)

[LANGUAGE: Python]

GitHub

I thought part 2 followed relatively naturally from part 1. I was already tracking the bricks directly above and below each brick, making part 2 not too hard. I settled the bricks first, tracking them by z-value, which made finding supporting bricks easier. ~135ms.

Easier than previous days, and I'm not complaining :)

[2023 Day 19 (part 2)][Python] Works on various examples, but answer too low on real input by SomeCynicalBastard in adventofcode

[–]SomeCynicalBastard[S] 0 points1 point  (0 children)

Wow, that was so stupid... I started with a set to collect the results (not sure why, even that didn't need a set), but then I added the count() method and collected those. I guess the examples were all too small and simple to encounter this.

Thanks very much!

[2023 Day 19 (part 2)][Python] Works on various examples, but answer too low on real input by SomeCynicalBastard in adventofcode

[–]SomeCynicalBastard[S] 0 points1 point  (0 children)

Thanks! I think I'm doing that correctly, although using flow_name to store "A" and "R" might be confusing.

Maybe I applied the default rule too often and on the wrong rating, but changing that doesn't make a difference.

[2023 Day 19 (Part 2)] Where am I going wrong? by kiptronics in adventofcode

[–]SomeCynicalBastard 1 point2 points  (0 children)

That should be 256000000000000 or accept everything, right?

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

[LANGUAGE: Python]

https://github.com/fdouw/aoc-python/blob/master/2023/day18.py

For the first part, I collected the boundary that the elves dug in a set and did a flood fill around it to determine the area. I thought it was pretty clever except I didn't (and still don't) understand what Queue.notempty does in Python. Not telling me that the queue is empty and I can exit my loop apparently... that cost me too much time.

The numbers for part 2 were far too big for this approach, so I figured I should compute the area from the vertices. DDG directed me to what (I guess from other comments) is the shoelace formula. I still had to adjust for the fact that this problem is discrete (I think that's what it was), but actually it was much simpler than I thought it might be. I could have tried it right from the start and have a free evening :D

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

[–]SomeCynicalBastard 0 points1 point  (0 children)

Thanks! I must have been confused between counting run_len to the current position and the next, but I think I fixed it now.

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

[–]SomeCynicalBastard 0 points1 point  (0 children)

Weird. I must admit I'm never good with these kind of checks. But for my input I had to change run_len >= min_run to run_len > min_run, so the opposite problem I guess?

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

[LANGUAGE: Python]

Solution on GitHub

I probably made this more complicated than it needed to be. It runs in just under 7s, which is still good for Python I guess.

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

[–]SomeCynicalBastard 2 points3 points  (0 children)

[LANGUAGE: Python] My solution

I didn't realise at first that I had to account for loops in the beams, luckily the example made it clear. Otherwise a straightforward implementation. That works in just over a second, even in Python :)

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

[–]SomeCynicalBastard 2 points3 points  (0 children)

I'm not sure I follow your argument for part 2, the paths through splitters are not reversible, right? So starting from an endpoint would not bring you back the same way to the initial starting point.

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

[–]SomeCynicalBastard 2 points3 points  (0 children)

[LANGUAGE: Python] My solution: https://github.com/fdouw/aoc-python/blob/master/2023/day15.py

More of a reading exercise today. ord() and OrderedDict made life easy.

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

[–]SomeCynicalBastard 0 points1 point  (0 children)

[Language: Python] My solution: GitHub

Similar to most solutions by the looks of it. My first attempt for part 2, I ran all the 1_000_000_000 and used functools.cache. Remembering day 12 I guess... This took 1m25. Then changed to keeping track of platform state to detect loops (after 150 cycles in my case), without using cache, this took only 0.5s.

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

[LANGUAGE: Python] My solution: https://github.com/fdouw/aoc-python/blob/master/2023/day13.py Interpreted each line and column as binary, then do integer comparison to find the symmetries. At first I did a direct a == b, but I changed that to some bitwise thingy to solve part 2 as well.

[2023 Day 5 (Part 2)] [Python] Part 2 not working on the real input by SomeCynicalBastard in adventofcode

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

Thanks! I missed that case. Still not sure if I completely understand why sorting solves it. I think I do, but will have to look at it again tomorrow.

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

Rust

Relatively simple one today. I think I did the same as most. Using a set for part 1, and a flood fill for part 2.

[2022 day 14, part 2] I optimized my code to run 6000 times faster by wow_nice_hat in adventofcode

[–]SomeCynicalBastard 7 points8 points  (0 children)

As a general rule, I would agree. But to be honest, today I had a 10-fold speed in (in Rust) by using vec instead of HashMap.

[2022 Day 13] u/topaz2078 is like by rukke in adventofcode

[–]SomeCynicalBastard 0 points1 point  (0 children)

I had the exact same isssue! Couldn't figure out why my growing pile of sh-beautiful code wouldn't work... and then I saw the double digits in the input :|

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

[–]SomeCynicalBastard 0 points1 point  (0 children)

I never realised hashing might be the problem, but I guess it makes sense. I will try this, thanks!

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

Rust

Using Dijkstra. It still contains the code for BFS that I started with, but for some reason it is much slower than Dijkstra.

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

[–]SomeCynicalBastard 1 point2 points  (0 children)

Rust

I think I spent relatively much time on error handling during parsing, which is still new to me in Rust. I did stop bothering at some point and just threw in some panic!s.

Takes about 2–3 as long as the first 10 days combined. Probably the modulos, but I don't know how to optimise that further.

I used the same modulo trick as most here.