aoc2024/day-10/internal/two/util.go

40 lines
634 B
Go
Raw Permalink Normal View History

2024-12-10 21:45:16 +00:00
package two
import (
"bufio"
"io"
"regexp"
log "github.com/sirupsen/logrus"
)
var reStartPos = regexp.MustCompile(`0`)
func parseLines(r io.Reader) (*graph, error) {
graph := newGrid()
var linecount int
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Text()
graph.data = append(graph.data, line)
for _, m := range reStartPos.FindAllStringIndex(line, -1) {
graph.startPositions = append(
graph.startPositions,
2024-12-10 22:04:52 +00:00
point{x: m[0], y: linecount},
2024-12-10 21:45:16 +00:00
)
}
linecount++
}
log.Debug(graph.startPositions)
if err := scanner.Err(); err != nil {
return nil, err
}
return graph, nil
}