adventofcode/2018/internal/day10/input.go

40 lines
710 B
Go
Raw Normal View History

package day10
import (
"regexp"
"strconv"
"strings"
)
func ParseInput(data []string) []*Point {
points := []*Point{}
regex := regexp.MustCompile("position=<(.*)> velocity=<(.*)>")
for _, line := range data {
p := &Point{}
matches := regex.FindSubmatch([]byte(line))
p.X, p.Y = parseVector2(string(matches[1]))
p.Xv, p.Yv = parseVector2(string(matches[2]))
points = append(points, p)
}
return points
}
func parseVector2(data string) (int, int) {
dataBuffer := strings.Split(data, ", ")
x, err := strconv.Atoi(strings.TrimSpace(dataBuffer[0]))
if err != nil {
panic(err)
}
y, err := strconv.Atoi(strings.TrimSpace(dataBuffer[1]))
if err != nil {
panic(err)
}
return x, y
}