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