aoc2024/day-12/internal/one/util.go

36 lines
569 B
Go
Raw Normal View History

2024-12-13 10:02:48 +00:00
package one
import (
"bufio"
"io"
"maps"
)
func parseLines(r io.Reader) (*graph, error) {
graph := newGraph()
scanner := bufio.NewScanner(r)
for scanner.Scan() {
graph.data = append(graph.data, scanner.Text())
}
if err := scanner.Err(); err != nil {
return nil, err
}
return graph, nil
}
func replaceAtIndex(s string, r rune, i int) string {
out := []rune(s)
out[i] = r
return string(out)
}
func firstPointFromMap(visited map[point]struct{}) point {
for k := range maps.Keys(visited) {
return k
}
panic("unable to fetch points from map")
}