package one import ( "bufio" "io" "regexp" ) var reMatchAntennae = regexp.MustCompile(`[a-zA-Z0-9]`) func parseLines(r io.Reader) (*graph, error) { graph := newGraph() var linecount int scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Text() graph.data = append(graph.data, line) for _, m := range reMatchAntennae.FindAllStringIndex(line, -1) { graph.antennae = append( graph.antennae, newAntenna(m[0], linecount, rune(line[m[0]])), ) } 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) }