fn main [ const d2dx := [ 0, 1, 0, -1 ]; const d2dy := [ -1, 0, 1, 0 ]; 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); var energized := array_fill(uint8, 0, [x, y]); var queue := [ mktuple3(0, 0, 1) ]; while len_greater_than(queue, 0) do [ var q := queue[0]; queue := 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; ] var sum := list_fold(0, array_to_list(energized), lambda(x : int, y : uint8) [ return x + select(y <> 0, 0, 1); ]); write(h[1], ntos(sum) + nl); ]