package two import ( "bytes" "math" "github.com/onyx-and-iris/aoc2024/day-20/internal/one" "github.com/onyx-and-iris/aoc2024/day-20/internal/point" log "github.com/sirupsen/logrus" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) graph, err := parseLines(r) if err != nil { return 0, err } log.Debugf("\n%s\n", graph.debug(one.Path)) var count int for pair1 := one.Path.Front(); pair1 != nil; pair1 = pair1.Next() { for pair2 := one.Path.Front(); pair2 != nil; pair2 = pair2.Next() { if manhatten(pair1.Key, pair2.Key) > 20 || pair1.Value-pair2.Value-manhatten(pair1.Key, pair2.Key) < 100 { continue } count++ } } return count, nil } func manhatten(a, b point.Point) int { return int(math.Abs(float64(a.X)-float64(b.X)) + math.Abs(float64(a.Y)-float64(b.Y))) }