Pastey Day 17 part 2

sequence curr = {0}
for p = length(pgm) to 1 by -1 do 
    sequence next = {} 
    for a in curr do 
        for b=0 to 7 do 
            if emulate(a*8+b,0,0,pgm,true)=pgm[p] then 
                next &= a*8+b 
            end if 
        end for 
    end for 
    curr = next 
end for 
-- solution in curr[1]

1. Comment by petelomax 5 days ago

BTW, it invokes emulate() a mere 656 times on the way to finding the correct solution.