package one import ( "bufio" "io" "strconv" "strings" ) func mustConv(s string) int { n, err := strconv.Atoi(s) if err != nil { panic(err) } return n } func parseLines(r io.Reader) ([]equation, error) { equations := []equation{} scanner := bufio.NewScanner(r) for scanner.Scan() { parts := strings.Split(scanner.Text(), ":") res := mustConv(parts[0]) var operands []int for _, s := range strings.Fields(parts[1]) { operands = append(operands, mustConv(string(s))) } equations = append(equations, newEquation(res, operands)) } if err := scanner.Err(); err != nil { return nil, err } return equations, nil }