package two import ( "bufio" "io" "strings" ) func parseLines(r io.Reader) (*graph, error) { graph := newGraph() var linecount int scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Text() r, indx := indxForAny(line, []rune{'S', 'E'}) if indx != -1 { if r == 'S' { graph.start = newNode(indx, linecount, E) } else { graph.end = newNode(indx, linecount, 0) } } graph.data = append(graph.data, line) linecount++ } if err := scanner.Err(); err != nil { return nil, err } return graph, nil } func indxForAny(s string, runes []rune) (rune, int) { for _, r := range runes { indx := strings.Index(s, string(r)) if indx != -1 { return r, indx } } return 0, -1 } func replaceAtIndex(s string, r rune, i int) string { out := []rune(s) out[i] = r return string(out) }