Advent of Code 2024

Let’s do this (Advent of Code) thing again!

I’m sticking with Rust again. I still use Python when I need to hammer out something quickly, but if I want to do something correctly (and especially if I want it to be fast), you can’t beat Rust.

Let’s see how it goes!

Full solutions will once again be posted to GitHub (including previous years and possibly some I haven’t written up yet): jpverkamp/advent-of-code

As we go, this will list all posted days:

And here are my previous year’s solutions:

I’m moving a bit this year, using the (so far) wonderful cargo-aoc library. I’d seen that in previous years, but hadn’t quite gotten around to using it. So far, it makes things really nice!

Basically, you set up cargo-aoc:

$ cargo install cargo-aoc
$ cargo aoc credentials ...
$ cargo add aoc-runner aoc-runner-derive

# To set up a new day
$ cargo aoc --generate --day 1

# To download my input (why we had credentials)
$ cargo aoc input --day 1

# To run a given day (leave off --day 1 to run the most recent)
$ cargo aoc --day 1

# Benchmarks!
$ cargo aoc bench --day 1

All basically for free!

All we have to do is have the project with:

// == In main.rs ==
aoc_main! { lib = aoc2024 }

// == In lib.rs ==
pub mod day1;
// ...

aoc_lib!{ year = 2024 }

// == Then solutions, for example day1.rs ==

#[aoc(day1, part1, i32)]
pub fn part1(input: &str) -> i32 {
  // ...
}

#[aoc(day1, part2, i32)]
pub fn part2(input: &str) -> i32 {
  // ...
}

You can return anything that impl Display, so for now numeric types are it.

Pretty cool, we’ll see if it sticks through the entire year.

At some point, I’m going to have to dig into those macros and see how they did it!