You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Jack Jackson 8770497049 Solution to 21-1
Phewf - this was a tough one! As I call out in the comments on 21.zig,
I had cracked _most_ of the shortcutting to this, but hadn't noticed
that choice of order-of-operations was not arbitrary - needed to notice
that doing a < before a ^ ends up more efficient than the other way
around, for instance.

I shudder to think what part 2 is going to be like...

For the record, my attempts at this took 1253 lines, over two files -
considering my total line count so far is 6233, that's over one-fifth.
Wild!
2 weeks ago
inputs Solutions to part 20 2 weeks ago
solutions Solution to 21-1 2 weeks ago
.gitignore Solution to 16-1 3 weeks ago
NOTES.md Solution to 18-1 3 weeks ago
README.md Finishing up on question 10-2 1 month ago
main.zig Solution to 1-2 2 months ago
test.sh Factor-out getInputFile 2 months ago

README.md

(Zig) solutions to the 2024 Advent Of Code.

If you - like me - are new to the Zig language, Ziglings seems to be a well-respected entrypoint!

The authoritative source for this code is on Gitea. The GitHub version is a mirror. Self-hosting is not only the best way to learn, but also to reduce dependency on untrustworthy corporations.

Execution

I've tried (in main.zig) to make a general-purpose executable that can be passed arguments to determine the function to run (e.g. zig run main.zig -- 1 2), but so far no luck - lots of type errors 🙃

So for now, run directly with (e.g.) zig run solutions/01.zig, and do the following manual changes:

  • Change pub fn main() void {...} in each solution-file to invoke the function you want run.
  • Change isTestCase from true to false when ready to get the real solution.

Code Quality

AoC challenges almost always have a "twist" partway through, meaning that you can solve the second part by injecting one subtly-different piece of logic into the solution to the first part - a different way of calculating a value or identifying candidates. If I were trying to show off for an interview (and were more comfortable with the language!), I would do the refactoring "right" by factoring out the common setup and execution logic to sub-functions, so that part_one and part_two are each single-line invocations of a common execute function with differing functions passed as parameter. But this is just an exercise for myself to learn the language - I'd rather get to grips with challenging problems to learn techniques, than to learn the (language-agnostic) skills of refactoring that I am already reasonably proficient with.

Retrospective

I aimed to complete as many problems as I could by the end of 2024, and as of writing this (at 17:02 on 2024-12-31, with a NYE party to get to), it looks unlikely that I'll get beyond Day 10. That's one better than last year's - and considering that I got married during this December, I think that's a pretty respectable showing 😅 I'd definitely like to go back and complete all the problems during January, though, as well as keep asking the helpful folks in Ziggit.dev more newbie-questions to help me actually understand the language rather than simply shuffling ideas around until I get a non-erroring result.