Categorygithub.com/ThePants999/advent-of-code-2024
repositorypackage
0.0.0-20241225053355-4d87eec3b28b
Repository: https://github.com/thepants999/advent-of-code-2024.git
Documentation: pkg.go.dev

# README

Advent of Code 2024 - Go

A complete set of solutions to the Advent of Code 2024 puzzles, written in Go.

I used AoC this year to learn Go - I hadn't written a line of it before December 1st. So this isn't the repository to look at if you're after beautiful examples of idiomatic Go. I also haven't got the absolute best algorithm for every day; programmers who really know their algorithms could no doubt significantly improve on what's here.

What I do have here is consistently Pretty Decent™ solutions. I set out with the goal of having a total cumulative runtime for all 25 days together of under a second, but I knocked that out of the park - I've actually managed a total runtime of under 60ms on my machine (Ryzen 5600X), with every single day executing under 10ms, and half under 1ms. There's also enough commenting that you should be able to follow what's going on. So hopefully this will be a useful repository for anyone wanting inspiration for what a Pretty Decent™ solution looks like for any given day.

Screenshot showing total runtime under 60ms

Framework

It also showcases the value in having a framework. If you take a glance at the code in here, you'll see that upwards of 99% is directly solving AoC problems, as everything like downloading/caching inputs or timing execution is taken care of by my framework - https://github.com/ThePants999/advent-of-code-go-runner. It's not currently robust or well-documented, so it won't impress you, but it might inspire you to create your own if you don't have one. Or, if you don't care about that robustness malarkey and you're writing Go yourself, you're free to use it.

Running the code

If you want to execute these solutions yourself, it's pretty simple, assuming you have Go installed:

git clone [email protected]:ThePants999/advent-of-code-2024.git
cd advent-of-code-2024
go build
./advent-of-code-2024 -a

You'll be prompted for your session cookie so that it can download your inputs for you.

Execution times

Averages over a thousand executions.

DayMedianMean
195µs114µs
2168µs198µs
3181µs208µs
4843µs769µs
5942µs727µs
67.034ms7.336ms
76.622ms7.475ms
8257µs276µs
93.960ms3.664ms
101.44ms1.471ms
117.867ms8.201ms
128.412ms8.875ms
1318µs26µs
14592µs684µs
15603µs704µs
166.994ms5.489ms
1727µs32µs
18543µs696µs
192.416ms2.66ms
202.574ms2.912ms
2125µs24µs
227.107ms9.096ms
232.076ms2.066ms
2480µs107µs
25412µs319µs