mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
36 lines
569 B
Go
36 lines
569 B
Go
|
package two
|
||
|
|
||
|
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")
|
||
|
}
|