package two import ( "bufio" "io" "strconv" "strings" "github.com/onyx-and-iris/aoc2024/day-18/internal/config" ) func parseLines(r io.Reader, config config.Config) (*graph, [][]int, error) { corruptedCoords := [][]int{} scanner := bufio.NewScanner(r) for scanner.Scan() { corruptedCoords = append(corruptedCoords, func() []int { x := strings.Split(scanner.Text(), ",") return []int{mustConv(x[0]), mustConv(x[1])} }()) } if err := scanner.Err(); err != nil { return nil, nil, err } graph := newGraph(config.Width, config.Height, config.NumCorruptions, corruptedCoords) return graph, corruptedCoords, nil } func mustConv(s string) int { n, err := strconv.Atoi(s) if err != nil { panic(err) } return n } func replaceAtIndex(s string, r rune, i int) string { out := []rune(s) out[i] = r return string(out) }