fn main [ var lines := list_break_to_lines(read_lazy(h[0])); const x := len(lines[0]); const y := len(lines); var a := list_to_array([x, y], list_join(lines, "")); a := array_flatten(a); fn solve_case(ini : tuple3(int, int, int)) : int [ const d2dx := [ 0, 1, 0, -1 ]; const d2dy := [ -1, 0, 1, 0 ]; var energized := array_fill(uint8, 0, [x, y]); var queue := [ ini ]; while len_greater_than(queue, 0) do [ var q := queue[len(queue) - 1]; queue := queue[ .. len(queue) - 1]; if q.v1 < 0 or q.v1 >= x or q.v2 < 0 or q.v2 >= y then continue; if energized[q.v1, q.v2] bt q.v3 then continue; energized[q.v1, q.v2] bts= q.v3; var ch := a[q.v1, q.v2]; if ch = '\' then q.v3 := q.v3 xor 3; if ch = '/' then q.v3 := q.v3 xor 1; if ch = '.' or ch = '\' or ch = '/' or ch = '-' and q.v3 bt 0 or ch = '|' and not q.v3 bt 0 then [ q.v1 += d2dx[q.v3]; q.v2 += d2dy[q.v3]; queue +<= q; continue; ] else if ch = '-' or ch = '|' then [ for x in [1, 3] do [ var d := q.v3 xor x; queue +<= mktuple3(q.v1 + d2dx[d], q.v2 + d2dy[d], d); ] ] else abort; ] return list_fold(0, array_to_list(energized), lambda(x : int, y : uint8) [ return x + select(y <> 0, 0, 1); ]); ] var ini := empty(tuple3(int, int, int)); for i := 0 to x do [ ini +<= mktuple3(i, 0, 2); ini +<= mktuple3(i, y - 1, 0); ] for j := 0 to y do [ ini +<= mktuple3(0, j, 1); ini +<= mktuple3(x - 1, j, 3); ] var m := list_map_fold(0, ini, solve_case, lambda(x y : int) [ return max(x, y); ]); write(h[1], ntos(m) + nl); ]