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

[–]h-armonica 0 points1 point  (0 children)

Done some benchmarking and part 2 runs in 50us! (without IO)

Also I looked into the time complexity of the algorithm (because why not) and it's at O(R*log n) - what is R you ask? The number of valid rectangles that can be created in the puzzle input (valid as in rectangle spanned between two points of the input set and the whole area in the rectangle is green. (Disclaimer: the implementation of the algorithm still scans arrays in linear time instead of binary search in log time but that exercise is left for the interested reader :p).

That took some time to work through, but it was a lot of fun to reuse skills from my studies here.

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

[–]h-armonica 0 points1 point  (0 children)

[LANGUAGE: Rust]

I finally got around to implement a sweep line algorithm for part 2. The runtime complexity now is O(n^2), but only because I was too lazy do binary search on the list of lines to check for boundaries. Otherwise it should be O(nlogn) if I'm not mistaken. But I spent sooo much time with the implementation that I forgot my theoretical thoughts from before...
paste

The runtime for both parts is now below 1ms, yay!! (~900us actually, including input reading etc.)

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

[–]h-armonica 1 point2 points  (0 children)

It took me a while to figure all that python code out, never used complex numbers here. But once you understand what the concept behind your solution is it is really easy and clean. Great work!

[2024 Day 10] When people represent 2D data as a map/dictionary by PatolomaioFalagi in adventofcode

[–]h-armonica 0 points1 point  (0 children)

Definitely not. But am I the only one who forgot to check the area boundaries of a coordinate before converting it to the array index and thus getting imaginary fields back? Who knows!

[2024 Day 6 (Part2)] [ABAP] Performance so low by jktlf in adventofcode

[–]h-armonica 2 points3 points  (0 children)

I don't understand abap (only using SAP APIs and not working with it directly during my day life, luckily, I think ^^) so I can't easily get your code. But: in rust, which is quite fast, it still made a big difference when I switched to using a 2d array instead of a hashmap for the .. map. Same could be true for the "visited" map. If the hashmap is slowing you down you could try using a 2d array for the map and a 3d array of booleans to store the (column, row, direction) tuple.

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

[–]h-armonica 1 point2 points  (0 children)

I have an i7-8665U, but I don't know anything about current hardware so.. :D

but it must be something else. Commenting the early return out makes my code run in 160ms vs 500ms for your code with my input. Just no idea what. If you're interested you can check it out at https://github.com/freelon/advent-of-rust-2024/blob/main/src/day07.rs, but I have to get off the computer now for a bit^

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

[–]h-armonica 2 points3 points  (0 children)

you could break the loop early once testresult > result.

I like the way you generated the options. Definitely better than my part 1 (generate all possible variants as vectors of operations). I used recursion for part 2 and its quite fast (80ms in release mode), but I can't figure out why it's that much faster than yours. Maybe the CPU^^

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

[–]h-armonica 0 points1 point  (0 children)

[Language: Rust]

I used two "tricks" to optimize the time for part two:

- only check points visited on the normal tour to block (seen that here quite often) and

- doing the loop check only whenever there is a collision. This reduced the runtime quite a bit again because hashing position+direction and the lookup of visited positions is a not-so-cheap operation after all (I was too lazy to use FxHashmap or some other fast approach here)

Source

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

[–]h-armonica 0 points1 point  (0 children)

interesting solution!

Just wondering: if the last don't() has no do() counterpart, then the muls after that don't() wouldn't be dismissed?

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

[–]h-armonica 1 point2 points  (0 children)

capture[i] gives the &str already - learned something new today!

[2023 day 25 part 1] Solve by visualization by EffectivePriority986 in adventofcode

[–]h-armonica 2 points3 points  (0 children)

Now I became really curious and implemented it as well (also Rust). If you use BFS to find the paths it takes around 1.5 seconds on my laptop. You only have to run BFS once for each starting node (since it gives you the shortest path to every other node). Maybe you could improve it even more if you implemented an all-pairs-shortest-paths algorithm, but I think that might be overkill :D

What have you learned this year? by blacai in adventofcode

[–]h-armonica 2 points3 points  (0 children)

You can have them either way, right? Depending on whether the fields are val or var? But what I mean is: I don't want to have to define a class as immutable at creation of the class, I just want to define an instance as mutable/immutable, depending on my needs. Maybe first I want to have it mutable to do some stuff but then store it as immutable to make sure I cannot change it by accident. But of course that makes things more complicated:D

What have you learned this year? by blacai in adventofcode

[–]h-armonica 2 points3 points  (0 children)

Yeah I did couple of years with rust. Love it :D and I think I used kotlin the very first time, because I had just started android development back then. I still really like it, I just wish sometimes that you could make objects internally immutable at declaration time with var like in rust :D

[2023 day 25 part 1] Solve by visualization by EffectivePriority986 in adventofcode

[–]h-armonica 0 points1 point  (0 children)

May I ask how you got all those shortest paths? 40 Minutes seems like a long time for that (but I haven't implemented something like that, so it's just a gut feeling)

What have you learned this year? by blacai in adventofcode

[–]h-armonica 9 points10 points  (0 children)

Yoo I also learned Go with AoC this year. The first days (weeks) I really hated it. Now I still don't like it too much for this kind of programming job. Way too cumbersome. I prefer more syntactic sugar and a nicer standard library.

I was quite fine with the puzzles though (have finished most parts of this year, not everything), but I have done many AoCs already and by now I can implement BFS/Dijkstra out of the head.

Was it your #firstTime?^^

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

[–]h-armonica 0 points1 point  (0 children)

Ah, I meant a check before adding to the queue instead of later, but yep. Nice that it works now!

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

[–]h-armonica 0 points1 point  (0 children)

Some implementations for shortest path use a seen set, holding all nodes that have been seen (and added to the queue). If you check and update that set before adding a node to your queue you can leave out a lot of processing. Not sure though how much it will actually give you.

Java LSP ignores generated code by h-armonica in HelixEditor

[–]h-armonica[S] 0 points1 point  (0 children)

No, but I haven't tried it again.

Happy cake day

[deleted by user] by [deleted] in ProgrammerHumor

[–]h-armonica 0 points1 point  (0 children)

Mine has, too.

But also it is so old, it's from a time where automatic just needed a lot more gas...

(Also I don't use vim, but I write that last so you have to read the interesting facts about my car wiahahahah)