I also like it since I don't do any work or even side projects in C these days, and so it's nice to keep my C chops up to scratch.
I also like it since I don't do any work or even side projects in C these days, and so it's nice to keep my C chops up to scratch.
The trick I used was to represent signed volumes, compute the intersection and then store the 'negative cube' instead of splitting up cubes.
My 2021 (Rust) solutions all meet that, but some only do so when optimized, and day 22 was one of those where without the optimizer I'm waiting 2-3 seconds for an answer.
IIRC the trick was to compact the indices, so e.g instead of thinking about X values of 120203 494302 and 109383 you call those 1, 2, 0. Do all the working out of which cells within the resulting tiny structure are on or off, and then expand the 1x1 cells you're talking about to their true size based on the real values instead of indices.
https://github.com/forrestthewoods/aoc2021/blob/master/rust/...
What kinds of optimisations have you had to do? Are you hosting your code anywhere?
I don't necessarily want to share my github as it contains my real name, but I'd be willing to send you a tarball of my 2020 code tomorrow if you send an email to mtlmtlmtlmtl at pm.me
I've just now started on day 1 for this year, so no code there yet worth showing off.
You can use the same hash function for any arbitrary struct as long as there's no pointers in it. If there are pointers, you'd have to implement one combining the hashes of all the members through something like xor. I used fnv1a_64 for my hash function in AOC 2020 which is a pretty good general choice for strings and other contiguous objects and is just 10 lines of code. Pseudocode on Wikipedia or I'm sure you can find C code on Stackoverflow. Hope that helps :)
If it's just a My First Hash table with closed addressing, buckets etc. you needn't care too much. If you're hashing integers, just use the integer itself, that's a terrible "hash" but with this like 1980s data structure it's good enough.
Worth noting that for AOC I got by just fine with the simplest possible bucket based implementation.