Partial solution for 10.1. We've got grouping, but still need sorting and some printing cleanup.

This commit is contained in:
Anna Rose Wiggins 2018-12-12 13:18:53 -05:00
parent 06a0886b67
commit e47b6c4a45
No known key found for this signature in database
GPG key ID: 8D9ACA841015C59A
6 changed files with 328 additions and 0 deletions

View file

@ -0,0 +1,39 @@
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
}