To use up less steps, I created 8 head versions of the programs, going both directions at once.

Or in the case of part 2, going both right and down.

In both cases I have to detect, that I have run into the work of another set of heads. I keep track of my state using the 2 extra heads. O for being on the outside of the “rectangle”, I for inside.
And that’s it. Thanks for reading along.