Partial solution for 10.1. We've got grouping, but still need sorting and some printing cleanup.
This commit is contained in:
parent
06a0886b67
commit
e47b6c4a45
6 changed files with 328 additions and 0 deletions
39
2018/internal/day10/input.go
Normal file
39
2018/internal/day10/input.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue