mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
35 lines
590 B
Go
35 lines
590 B
Go
|
package two
|
||
|
|
||
|
import (
|
||
|
"bufio"
|
||
|
"io"
|
||
|
"regexp"
|
||
|
)
|
||
|
|
||
|
var reMatchAntennae = regexp.MustCompile(`[a-zA-Z0-9]`)
|
||
|
|
||
|
func parseLines(r io.Reader) (*graph, error) {
|
||
|
graph := newGraph()
|
||
|
|
||
|
var linecount int
|
||
|
scanner := bufio.NewScanner(r)
|
||
|
for scanner.Scan() {
|
||
|
line := scanner.Text()
|
||
|
graph.data = append(graph.data, line)
|
||
|
|
||
|
for _, m := range reMatchAntennae.FindAllStringIndex(line, -1) {
|
||
|
graph.antennae = append(
|
||
|
graph.antennae,
|
||
|
newAntenna(m[0], linecount, rune(line[m[0]])),
|
||
|
)
|
||
|
}
|
||
|
linecount++
|
||
|
}
|
||
|
|
||
|
if err := scanner.Err(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return graph, nil
|
||
|
}
|