Reverse-engineering the program from “Chronospatial Computer”, day 17 of Advent of Code 2024.
At codegolf.stackexchange.com, smaller is better.