package one import ( "bytes" "slices" "github.com/onyx-and-iris/aoc2024/day-05/internal/util" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) updates, orderings, err := util.ParseLines(r) if err != nil { return 0, err } var sum int for _, update := range updates { beforeSort := slices.Clone(update.Pages) update.Sort(orderings) if slices.Compare(beforeSort, update.Pages) == 0 { sum += update.Pages[len(update.Pages)/2] } } return sum, nil }