A run of consecutive matching lines is a free ride across the edit graph - Myers calls it a snake. Today you write the helper that follows one as far as it goes, the move that makes the algorithm cheap.
From a grid point, follow consecutive diagonal matches to the furthest reachable point.
A snake is a maximal run of diagonal moves - a stretch of lines the two documents share consecutively. Because diagonals are free, once you arrive at a point you should always take every diagonal available before spending another edit; there is never a reason to stop a match early. snake does exactly that: it walks diagonally, calling the predicate from the last lesson, until the lines stop matching or it runs off the end of a document.
This is the single most important move in Myers’ algorithm. Every edit (a right or a down) is immediately followed by sliding down whatever snake it opens onto, so the algorithm advances in big free jumps rather than one cell at a time. That is why it costs O((n+m)·D) where D is the number of edits, instead of the baseline’s O(nm): when two documents are similar, D is small and the snakes are long. Next you introduce the bookkeeping - the V array - that decides which edit to spend before each snake.
// slide diagonally while lines keep matchingfunc snake(a, b []string, x, y int) (int, int) {for canDiagonal(a, b, x, y) {x, y = x+1, y+1}return x, y}