Advent of Code calibration algorithm visualization

by kragen
GNU/Linux ◆ xterm-256color ◆ bash 77 views

A friend of mine had a hard time understanding a solution to a part of an Advent of Code problem where you’re supposed to convert strings like ‘sevenineoeo3seveightxon’ into lists of digits like [7, 9, 3, 8], so I made this animation to explain it better. It’s worth thinking about how a programming environment could make the original 2-line or 4-line program inspectable in this way, without having to bloat it up to 20 lines of code that can no longer be used to solve the original problem.

The algorithm being visualized is just

[digits[d] for p in range(len(s)) for d in digits if s[p:p+len(d)] == d]