feat: more elegant solution, get rid of cmp

This commit is contained in:
2025-11-26 17:12:36 +01:00
parent 59974a4d29
commit 62969312e3

View File

@@ -2,7 +2,6 @@ package dayone
import ( import (
"advent-of-code/internal/registry" "advent-of-code/internal/registry"
"cmp"
"os" "os"
"slices" "slices"
"strconv" "strconv"
@@ -50,13 +49,12 @@ func PartTwo(input []string) int {
} }
totals = append(totals, currentElf) totals = append(totals, currentElf)
slices.SortFunc(totals, func(a, b int) int { slices.Sort(totals)
return cmp.Compare(b, a) slices.Reverse(totals)
})
sum := 0 sum := 0
for idx := 0; idx < 3 && idx < len(totals); idx++ { for _, val := range totals[:min(3, len(totals))] {
sum += totals[idx] sum += val
} }
return sum return sum
} }