fn process_line(l : bytes) : int [ var colon := list_search(l, ':'); var result := ston(l[ .. colon]); var numbers := map(list_break_whitespace(l[colon + 2 .. ]), ston); for ops := 0 to 1 shl len(numbers) - 1 do [ for concat := 0 to 1 shl len(numbers) - 1 do [ if (concat and ops) <> 0 then continue; var n := numbers[0]; for i := 1 to len(numbers) do [ if concat bt i - 1 then n := ston(ntos(n) + ntos(numbers[i])); else if ops bt i - 1 then n *= numbers[i]; else n += numbers[i]; ] if n = result then return result; ] ] return 0; ] fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var sum := 0; for l in lines do sum += process_line~spark(l); write(h[1], ntos(sum) + nl); ]