Advent of Code 2024

This is the first year I want to participate in Advent of Code. In the past years I always skipped it, because .. yeah. Why not.

And, just because I can, I want to use a different programming language for every day. Nix provides me with the power to do so.

Every program is written such that it reads an example input from stdin and writes the transformed one to stdout.

You can run a specific part of a specific day directly via flake outputs. It is not needed to clone this repository, you could just run it on a system with a flake-enabled nix.

nix run github:jkuball/advent-of-code-2024#day-12-part2

# (keep in mind that this waits for input from stdin)

I am also providing the usual example input and my own challenge input.

nix run .#day-01-part1 < tests/__fixtures/day-01/baseline.txt

# or using the standard cli
std //code/challenges/day-01-part2:run < tests/__fixtures/day-01/challenge.txt

You can use the standard cli to explore this repository and everything it provides: nix run github:divnix/std.

Overview

DayStatus Part 1Status Part 2Language
01.12.2024DONEDONEbash (pkgs.writeShellApplication)
02.12.2024DONEDONEfish (pkgs.writers.writeFishBin)
03.12.2024🔜 OPEN🔒 LOCK
04.12.2024TBDTBD

Run the Tests

I am using namaka for snapshot based testing. This is the first time using std and namaka together, and I think I did some things weirdly, even wrongly. Maybe I will revisit this in the future.

But right now, to run the tests, one has to update the subflake first:

$ nix flake update --flake ./cells/tests
• Updated input 'aoc':
[...]

$ std //tests/checks/snapshots:check
✔ day-01-part1-baseline
✔ day-01-part1-challenge
✔ day-02-part2-baseline
✔ day-01-part2-baseline
✔ day-01-part2-challenge
✔ day-02-part2-challenge
✔ day-02-part1-baseline
✔ day-02-part1-challenge
All 8 tests succeeded

Code

Cell: code

No documentation

Block: nixpkgs

No documentation

Block: challenges

This block houses all the implementations for the different challenges.

Target: day-01-part1

No description

For this day I selected plain old bash file because it was the first thing that came to mind and it was easy to set up (thanks to pkgs.writeShellApplication), but after I was done, I felt really dirty.

But the thing is, it IS really dirty. I just said “everything that is available, I can use” – and it was way too much. Even awk was available. Thankfully, I at least had the dignity to not use that.

Target: day-01-part2

No description

Target: day-02-part1

No description

Today was way nicer than yesterday. I think, mostly because I felt not so dirty for just abusing every thing that was available to me. This challenge I just did everything with pure fish builtins. I think.

Only thing I missed were booleans. Are there booleans? There might be, maybe I just assumed there weren’t. Still, I think my is_{inc,dec}reasing check was slick.

Target: day-02-part2

No description