feat: more elegant solution, get rid of cmp
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user