aoc2024/day-01/internal/one/util.go

21 lines
278 B
Go
Raw Permalink Normal View History

2025-01-07 17:18:38 +00:00
package one
2024-12-01 17:50:02 +00:00
import (
"cmp"
"slices"
"strconv"
)
2025-01-07 17:18:38 +00:00
func mustConv(s string) int {
2024-12-01 17:50:02 +00:00
n, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return n
}
2025-01-07 17:18:38 +00:00
func insertSorted[T cmp.Ordered](ts []T, t T) []T {
2024-12-01 17:50:02 +00:00
i, _ := slices.BinarySearch(ts, t)
return slices.Insert(ts, i, t)
}