From 5f5ec795e779bc3d153b1efb1cc1b9b2fe551fd1 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sun, 17 Dec 2023 22:48:24 -0500 Subject: [PATCH] Minor reshuffling of day 15 part 2 --- day15/main.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/day15/main.go b/day15/main.go index 02d7929..e18198e 100644 --- a/day15/main.go +++ b/day15/main.go @@ -129,6 +129,21 @@ func part2(inputElements []string) int { operation(hm) } + return calculatePower(hm) +} + +func hash(s string) int { + res := 0 + for _, char := range s { + res += int(char) + res *= 17 + res %= 256 + } + + return res +} + +func calculatePower(hm HashMap[int]) int { power := 0 for i := range hm { boxEntries, err := hm.EntriesInBox(i) @@ -146,17 +161,6 @@ func part2(inputElements []string) int { return power } -func hash(s string) int { - res := 0 - for _, char := range s { - res += int(char) - res *= 17 - res %= 256 - } - - return res -} - // findInList finds the given element in the linked list. The element *MUST* be of the type V, or this will panic func findInList[V any](l *list.List, isEqual func(V) bool) *list.Element { for cursor := l.Front(); cursor != nil; cursor = cursor.Next() {