Advent of Code 2021


Update: I’ve rewritten the visualization and documented the process.

Every year, I attempt to complete the Advent of Code. It’s a series of programming challenges that gives me an opportunity excise my coding ability in new and unique ways.

I completed this year in the same manor I’ve used for the past few years: Swift command line applications with some visualizations done through CoreGraphics, AVFoundation, Metal , and SwiftUI . The solutions can be found on my GitHub page.

My Animator and RenderableWorkView stayed roughly the same from last year, but I did discover a terrible memory leak in the Metal renderer. C calls like CVMetalTextureCacheCreateTextureFromImage write to pointers, and in Swift, the Automatic Reference Counting misses that overwrite, causing every single texture generated to leak. For proper accounting, you must assign the texture to nil first, to ensure the previous texture gets cleaned up. Leaks like that are hard to find because Advent of Code challenges are sometimes designed to consume tons of memory if you aren’t paying attention.

Bingo with an octopus
Flashing dumbo octopuses
Folding transparent notes
Finding the least risky path