Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
This repo contains my solutions for this year's Advent of Code problem sets, written in Go. No one-liners here—we're doing this the hard way! I've organized each day's problem sets into Go modules and wrote a simple runner in main.go
to quickly iterate on the solutions.
I haven't used Go in a while, so I'm relearning the module system. I have a feeling that this project can be better organized. Suggestions are welcome :).
I've also included unit tests which run on every git push
via GitHub Actions—this makes the badge above all nice and green.
-
Each day has an associated problem set. Use
make init
to generate all the required files for each day. For example:make init FOLDER=day3
-
Add new case statements in
main.go
. -
Start writing code in the
${DAY}
folder. -
When you're ready to test, add unit tests in the
${DAY}
folder. Useday1/part2_test.go
as a template, and add a line to thetest
rule inMakefile
. Afterwards, run tests withmake test
. E.g.:$ make test go test github.com/dlo/aoc2021/day1 -cover ok github.com/dlo/aoc2021/day1 0.234s coverage: 100.0% of statements go test github.com/dlo/aoc2021/utils -cover ok github.com/dlo/aoc2021/utils (cached) coverage: 12.1% of statements
-
Run the command for a specific day:
$ go build $ ./aoc2021 --day 1 --part 1 --filename input.txt // Reads from day01/testdata/input.txt