package two import ( "bytes" "fmt" "github.com/onyx-and-iris/aoc2024/day-18/internal/config" "github.com/onyx-and-iris/aoc2024/day-18/internal/point" log "github.com/sirupsen/logrus" ) func Solve(buf []byte, config config.Config) (string, error) { r := bytes.NewReader(buf) graph, corruptedCoords, err := parseLines(r, config) if err != nil { return "", err } log.Debugf("start: %v end: %v", graph.start, graph.end) log.Debug(corruptedCoords) indx := runUntilNoPath(graph, corruptedCoords, config) return fmt.Sprintf("%d,%d", corruptedCoords[indx][0], corruptedCoords[indx][1]), nil } func runUntilNoPath(graph *graph, corruptedCoords [][]int, config config.Config) int { for i, coords := range corruptedCoords[config.NumCorruptions+1:] { nextCorruption := point.Point{X: coords[0], Y: coords[1]} log.Debugf("adding corruption %v", nextCorruption) graph.addCorruption(nextCorruption) ok := graph.bfs() if !ok { return config.NumCorruptions + i + 1 } } return 0 }