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() {