Minor reshuffling of day 15 part 2
parent
6817e25645
commit
5f5ec795e7
|
@ -129,6 +129,21 @@ func part2(inputElements []string) int {
|
||||||
operation(hm)
|
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
|
power := 0
|
||||||
for i := range hm {
|
for i := range hm {
|
||||||
boxEntries, err := hm.EntriesInBox(i)
|
boxEntries, err := hm.EntriesInBox(i)
|
||||||
|
@ -146,17 +161,6 @@ func part2(inputElements []string) int {
|
||||||
return power
|
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
|
// 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 {
|
func findInList[V any](l *list.List, isEqual func(V) bool) *list.Element {
|
||||||
for cursor := l.Front(); cursor != nil; cursor = cursor.Next() {
|
for cursor := l.Front(); cursor != nil; cursor = cursor.Next() {
|
||||||
|
|
Loading…
Reference in New Issue