Minor reshuffling of day 15 part 2

master
Nick Krichevsky 2023-12-17 22:48:24 -05:00
parent 6817e25645
commit 5f5ec795e7
1 changed files with 15 additions and 11 deletions

View File

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