mirror of
https://github.com/onyx-and-iris/aoc2023.git
synced 2024-11-21 18:00:47 +00:00
remove add, remove functions.
This commit is contained in:
parent
20713a9967
commit
e7635b5e4c
@ -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, "-"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user