2024-12-06 20:01:17 +00:00
|
|
|
package two
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"io"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseLines(r io.Reader) (*graph, error) {
|
2024-12-06 22:23:01 +00:00
|
|
|
graph := &graph{}
|
2024-12-06 20:01:17 +00:00
|
|
|
|
|
|
|
count := 0
|
|
|
|
scanner := bufio.NewScanner(r)
|
|
|
|
for scanner.Scan() {
|
|
|
|
line := scanner.Text()
|
|
|
|
indx := strings.Index(line, "^")
|
|
|
|
if indx != -1 {
|
|
|
|
graph.startPoint = point{indx, count, N}
|
|
|
|
}
|
|
|
|
graph.data = append(graph.data, scanner.Text())
|
|
|
|
count++
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|