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]{}
// 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
func two(lines []string) int {
hash := newHasher()
@ -38,9 +28,9 @@ func two(lines []string) int {
}
if strings.Contains(lense, "=") {
add(boxId, label, focalLength)
boxes[boxId].Set(label, focalLength)
} else {
remove(boxId, label)
boxes[boxId].Delete(strings.TrimRight(label, "-"))
}
}