Advent of Code 2021

Been a while since I’ve done an advent of code! I’ll probably backfill a few years eventually, but for now, let’s just write some code!

As always, these problems are wonderful to try to solve yourself. If you agree, stop reading now. This post isn’t going anywhere.

If you’d like to see the full form of any particular solution, you can do so on GitHub (including previous years and possibly some I haven’t written up yet): jpverkamp/advent-of-code

Here’s a full list of all of the posts:

And here’s the current testing harness I’m using:

problems = [
    [1, '01', 'Sonar Sweep', 'depth-finder.py', {
        'part1': 'input.txt',
        'part2': 'input.txt 3',
        'part2-simple': 'input.txt 3'
    }],
    ...
]

for day, folder, name, file, variants in problems:
    print(f'--- Day {day}: {name} ---\n')

    for cmd, args in variants.items():
        print(f'$ python3 {file} {cmd} {args}')

        start = time.perf_counter_ns()
        subprocess.check_call(f'python3 {file} {cmd} {args}', shell=True, cwd=folder)
        end = time.perf_counter_ns()

        print(f'# time {end-start}ns / {(end-start)/1e9:.2f}s\n')

And here are my previous year’s solutions: