fn main [ var lines := list_break_to_lines(read_lazy(h[0])); lines := list_flatten(lines); const x := len(lines[0]); const y := len(lines); var a := list_to_array([x, y], list_join(lines, "")); a := array_flatten(a); var xp yp dx dy : int; for i := 0 to x do [ for j := 0 to y do [ xp := i; yp := j; if a[i, j] = '^' then [ dx, dy := 0, -1; goto found; ] if a[i, j] = '>' then [ dx, dy := 1, 0; goto found; ] if a[i, j] = 'v' then [ dx, dy := 0, 1; goto found; ] if a[i, j] = '<' then [ dx, dy := -1, 0; goto found; ] ] ] abort; found: a[xp, yp] := '.'; var count := 0; while true do [ if a[xp, yp] = '.' then [ a[xp, yp] := 'X'; count += 1; ] turned: var nx, ny := xp + dx, yp + dy; if nx < 0 or nx >= x or ny < 0 or ny >= y then break; if a[nx, ny] = '#' then [ dx, dy := -dy, dx; goto turned; ] xp, yp := nx, ny; ] write(h[1], ntos(count) + nl); ]