~nilium/aoc2020

Add day 10 solution

There's more commentary in the code than the commit this time because
I spent about an hour or more trying to wrap my head around the
problem, then flailed around for a while longer with combinations of
runs of 1-sequences before getting a hint on Reddit about the
tribonacci sequence being useful for this. So, part 2 was dismal.
Interesting problem, but very tiring.
Add COPYING file

Add a BSD 2-clause license in case anyone wants to copy this.
Add day 9

This one was pretty boring and just involves a combination and
a sliding window. Since I had the combination type from day one, I just
reused that for part one. For part 2, the sliding window is easy enough
to do in a for loop (though it'd be fancier with an iterator-ish type).

Got to learn about std.sort, so time well spent.
Add day 8

This one just implements a simple VM to run the accumulator. The hits
array is a little unfortunate since I was being lazy. There is probably
a better way to indicate that a particular instruction was hit multiple
times, but it's not really necessary to do for this.

Part 2 involves mostly brute forcing the problem by just stepping
through the code with the VM and replacing jmp/nop instructions until
the correct one is found. When I submitted the answer, I eyeballed the
instructions after walking back through the code from the looping
point manually, so there was no code for part 2 until after submission
because it was frankly faster to do it by hand.

I'm not sure about the parseCode function. I'm not sure that it matters
to have a generalized parseCode function, but I felt like trying it.
Probably burned more time on that than the actual parsing.
Add day 7

Currently writing this in a house that's been almost pitch black for
several hours now due to a power outage. Also have a mild headache. Had
to submit my results via phone since tethering has been inconsistent
and only lasted long enough to get the sample input and real input
(included as input_rules.zig).

Most of the work here is in the two ruby files, each of which compiles
the source text to Zig or graphviz (the latter was just so I could
eyeball it and see if there were cycles).
Remove unused set variable
Replace bitsSet and bitsTrailingZeros with builtins

Replace bitsSet with the popCount builtin and bitsTrailingZeros with
the ctz builtin. That's more convenient than doing this myself.
Fix combination.zig tests

Replace expect use with expectEqual and expectEqualSlices where
relevant.
Remove commented out day 6 code

Day 6 was built from day 5, so some code was still in it from day 5,
but commented out. Just delete that.
Add day 6 package

Forgot to add day 6 to build.zig after refactoring the build.zig files.
Clean up build.zig

Just clean up the build function a bit and remove unused code.
Add day 6

Day 6 mostly just reuses the BitSet from day 5 for part one, then keeps
counts for part two. Nothing very sophisticated here. Briefly thought
about adapting the lexer but decided to save that for later if I really
need it.
Move lib types to lib/nil, top-level build

Create a top-level build.zig so that shared types and such can get
moved to lib/nil/. This is mostly a convenience so days 5 and 6 can
both use the bit functions and BitSet.

Re-add previously-removed bitsSet function to bits.zig to add a count
function to BitSet.
Add day 5 code

This one's pretty straight-forward but I ended up implementing part
2 with a bit set. Probably could've just kept track of any ID where
a subsequent ID was n+2, but this was more interesting. Lot of code
deleted from this one before committing because I spent a bunch of time
messing around with other bit functions and so on.
Move token lexing reset

This was bothering me because reading one stream of tokens and then the
other would be incorrect, but it's already incorrect with EOF handling,
so eh.
Add day 4 code

This one was fun. Wrote a lexer, albeit only a minimal one, to pull the
words and separators (two newlines) out of the input, since that seemed
like a better idea than trying to split and interate over things.
Probably wasn't necessary, but I like writing lexers, so this is fine.
Remove lines field from Counter struct

Added that for debugging, so just going to remove it now.
Add day 3

This one's pretty simple still. Just walks over lines and checks for
hits over a given stride. It was the first use I made of default field
values for structs, so learned something in the process.

Unlike last year (I think?), it seems like there's not a lot of
revisiting code yet. Maybe that'll change in day 4.
Use compileError instead of unreachable for compile-time error

Should've used this instead of the unreachable thing, but didn't know
about it at the time.
Remove use of libc allocator

This was making it annoying to build on Linux, so just use the arena
allocator.
Next