fn get_digit(s : bytes) : int [ if s[0] >= '0', s[0] <= '9' then return s[0] - '0'; var d := [ list_begins_with(s, "zero"), list_begins_with(s, "one"), list_begins_with(s, "two"), list_begins_with(s, "three"), list_begins_with(s, "four"), list_begins_with(s, "five"), list_begins_with(s, "six"), list_begins_with(s, "seven"), list_begins_with(s, "eight"), list_begins_with(s, "nine"), ]; return list_search(d, true); ] fn main [ var lines := list_break_to_lines(read_lazy(h[0])); var sum := 0; for line in lines do [ var first := -1; var last := -1; for i in list_iterator(line) do [ var digit := get_digit(line[i .. ]); if digit >= 0 then [ if first = -1 then first := digit; last := digit; ] ] sum += first * 10 + last; ] write(h[1], ntos(sum) + nl); ]