remove add, remove functions.

This commit is contained in:
onyx-and-iris 2023-12-15 19:51:15 +00:00
parent 20713a9967
commit e7635b5e4c

View File

@ -8,16 +8,6 @@ import (
var boxes = map[int]*orderedmap.OrderedMap[string, int]{} var boxes = map[int]*orderedmap.OrderedMap[string, int]{}
// add places a lense into an ordered box
func add(id int, label string, focalLength int) {
boxes[id].Set(label, focalLength)
}
// remove takes a lense out of an ordered box
func remove(id int, label string) {
boxes[id].Delete(strings.TrimRight(label, "-"))
}
// two returns the sum of all lense configurations // two returns the sum of all lense configurations
func two(lines []string) int { func two(lines []string) int {
hash := newHasher() hash := newHasher()
@ -38,9 +28,9 @@ func two(lines []string) int {
} }
if strings.Contains(lense, "=") { if strings.Contains(lense, "=") {
add(boxId, label, focalLength) boxes[boxId].Set(label, focalLength)
} else { } else {
remove(boxId, label) boxes[boxId].Delete(strings.TrimRight(label, "-"))
} }
} }