2022 Advent of Code

It’s almost time for Advent of Code and I’m going to try some of the challenges again this year, this time I’m trying Go though.

I first heard of Advent of Code a few years ago but never had the time/inclination to give it a go until 2019, when I earned the grand sum of 2 stars. Last year though I had an ideal opportunity to take part in AoC. I was moving teams to one which primarily used Python so I felt like I needed to brush up on my Python skills having last used it in 2002 (yes 20 years ago). So, with PyCharm downloaded I set about completing the tasks in a language that was quite unfamiliar to me.

Overall I was happy with the progress I made, I earned 32 stars and as time went on I get quicker at solving the challenges. I felt that AoC gave me challenging enough problems from the start, I didn’t have to wade through tons of basic problems first.

So, having had a positive experience last year, I’m going to try some of the challenges again this year but my language of choice will be Go.

The plan

My plan is to create a new folder for each days challenge and include a solution file and 1..n test files. My experience of 2021 is that the problem is given with 1..n small example solution(s), finally a bigger problem input. This fits well with my plan of having one or more test files.

Getting set up

Before I start on AoC 2022 I want to make sure I have some basics set up. I won’t give all the steps I’ve gone through to get set up but will detail what the setup will be.

First off I need a Go environment. I’ve got an M1 Mac so had to download the arm version from the Go website. Installation was easy and once complete I could use Go from the command line:

╰─❯ go version
go version go1.19.3 darwin/arm64

Next is the code editor. I’m a big fan of the Idea toolset but have decided to try and make do with Visual Studio Code and the Go plugin. We’ll see how far this takes me, if I’m really missing the awesome git client in GoLand I might swap.

One of the things I’ve used in the last 12 months with Python and like is pre-commit, this enables a number of validations to be run on source code at commit stage automatically. For my project I want to set up a pre-commit hook that will format my Go code so that it’s consistent across files but also with other Go projects… this makes it easier for all engineers to read. I’ve added a .pre-commit-config.yaml file with my configuration, in summary this will run go-mod-tidy and go-fmt each time I commit my files. If I get time I will also try some of the other validation tools like go-vet but for now I think my setup is good enough.

The final thing I wanted to have in place before I started the challenges was a GitHub action that would run any tests that I have created. My actions workflow will set up Go as part of the pipeline, then run go mod verify followed by staticcheck and finally run go test. Again this should be good enough for a pipeline for now, I’ll probably be running tests locally anyway but having the static checks as part of a test process will help to make sure the code stays clean once I think I have a solution.

That’s it, that’s the set up I’m going with and maybe it will evolve. Only a couple of days to wait now and I can see if this works when really put to the test.