Look up the b/s format for specifying rules. It is a lot more flexible.
Here's my version : https://github.com/chewxy/ll/blob/main/main.go#L176
I also live coded this in a series of 3 videos:
1. https://youtu.be/5JArQO8YeRo 2. https://youtu.be/ZLUVAWb_31M 3. https://youtu.be/BIypQF7M9c8
My approach differs from yours in that mine is entirely matrix driven.