20
SOLUTION MEGATHREAD-❄️- 2024 Day 22 Solutions -❄️-(self.adventofcode)
submitted 1 year, 1 month ago* (edited 12 minutes after) by daggerdragon to /r/adventofcode (134.8k)
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our [community wiki](https:...
since 1 year, 1 month ago
4 of 4
Tip Reveddit Real-Time can notify you when your content is removed.
your account history
Tip Check if your account has any removed comments.
view my removed comments you are viewing a single comment's thread.
view all comments


[LANGUAGE: dc (GNU v1.4.1)]
Just part 1. This is something you probably don't want to run. Dc does not have an XOR, I quickly implemented a 24-bit one (brain foggy day so its not the most efficient), and it took 90 minutes to run (on 15-year-old hardware, you'll probably have better).
Code: https://pastebin.com/pJz5nz2H
I was able to test it in much less time though, because many years ago, I embedded Perl in an older version of dc (v1.3) and still have that executable around from when I brought that out for AoC a few years ago. It required some maintenance then (the details for embedding Perl had changed a bit) to get it to compile, but it seems to work fine. I really should embed Perl properly in a newer version, because its convenient and cool.
Anyways, that allowed me to replace the dc XOR function with:
(The part in #s at the start tells it to only look at the top two elements, and pop (!) them... so this pops the top 2, and pushes the 24-bit XOR of those.)
So, I suppose this means that I have used a "language" (well, dialect) that I created this year. So, [LANGUAGE: edc] I guess (extended dc... that's what I called it). This allows the thing to complete in 90s instead of 90m. So that's the lower bound on what can be gained by improving the XOR implementation.
[removed] content loading...
Comment removed due to naughty language. Keep the megathreads professional.
Here's a faster version pulling out the stops. And by stops we mean making the code a long mess, because we're pre-allocating all the constants. That way they're parsed and created only once, and then copied from a registers (which is much, much faster).
The other thing I did was improve the XOR function quite a bit, by using the formula I have for a 2-bit XOR ((a + b*(-1)a) % 4) instead of a 1-bit XOR (like (a-b)2).
The overall effect is that this runs in 1/3rd the time of the original (so 30m).
Code: https://pastebin.com/c3idjSMM