mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
45 lines
780 B
Go
45 lines
780 B
Go
package one
|
|
|
|
import (
|
|
"bufio"
|
|
"io"
|
|
"strings"
|
|
|
|
"github.com/onyx-and-iris/aoc2024/day-20/internal/point"
|
|
)
|
|
|
|
func parseLines(r io.Reader) (*graph, error) {
|
|
graph := newGraph(make([]string, 0))
|
|
|
|
var linecount int
|
|
scanner := bufio.NewScanner(r)
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
|
|
if strings.Contains(line, "S") {
|
|
indx := strings.Index(line, "S")
|
|
graph.start = point.New(indx, linecount)
|
|
}
|
|
if strings.Contains(line, "E") {
|
|
indx := strings.Index(line, "E")
|
|
graph.end = point.New(indx, linecount)
|
|
}
|
|
|
|
graph.data = append(graph.data, line)
|
|
|
|
linecount++
|
|
}
|
|
|
|
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)
|
|
}
|