package one import ( "bufio" "io" "regexp" "strconv" ) var reRobot = regexp.MustCompile(`p=(?P\d+),(?P\d+) v=(?P-?\d+),(?P-?\d+)`) func parseLines(r io.Reader) ([]*robot, error) { var matches [][]string scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Text() m := reRobot.FindStringSubmatch(line) matches = append(matches, m) } if err := scanner.Err(); err != nil { return nil, err } var robots []*robot for _, m := range matches { robots = append(robots, newRobot(mustConv(m[1]), mustConv(m[2]), mustConv(m[3]), mustConv(m[4]))) } return robots, nil } func mustConv(s string) int { n, err := strconv.Atoi(s) if err != nil { panic(err) } return n }