From 62969312e3654c8397a1b2bc06b6ffe6c47a50ad Mon Sep 17 00:00:00 2001 From: Kharec Date: Wed, 26 Nov 2025 17:12:36 +0100 Subject: [PATCH] feat: more elegant solution, get rid of cmp --- internal/2022/DayOne/code.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/2022/DayOne/code.go b/internal/2022/DayOne/code.go index d12a534..b7bc4d3 100644 --- a/internal/2022/DayOne/code.go +++ b/internal/2022/DayOne/code.go @@ -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 }