fn get_reflection(puzzle : list(bytes), n : int) : int [ var x := len(puzzle[0]); var y := len(puzzle); for i := 1 to x do [ var d := 0; while true do [ if i - 1 - d < 0 or i + d >= x then [ if i = n then goto no_match1; return i; ] for j := 0 to y do if puzzle[j][i - 1 - d] <> puzzle[j][i + d] then goto no_match1; d += 1; ] no_match1: ] for j := 1 to y do [ var d := 0; while true do [ if j - 1 - d < 0 or j + d >= y then [ if j * 100 = n then goto no_match2; return j * 100; ] if puzzle[j - 1 - d] <> puzzle[j + d] then goto no_match2; d += 1; ] no_match2: ] return -1; ] fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var puzzles := list_break(lines, ""); var sum := 0; for puzzle in puzzles do [ var r1 := get_reflection(puzzle, -1); var x := len(puzzle[0]); var y := len(puzzle); for i := 0 to x do [ for j := 0 to y do [ puzzle[j][i] := '.' + '#' - puzzle[j][i]; var r := get_reflection(puzzle, r1); puzzle[j][i] := '.' + '#' - puzzle[j][i]; if r >= 0 then [ sum += r; goto next_puzzle; ] ] ] next_puzzle: ] write(h[1], ntos(sum) + nl); ]