mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
21 lines
279 B
Go
21 lines
279 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"cmp"
|
||
|
"slices"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func MustConv(s string) int {
|
||
|
n, err := strconv.Atoi(s)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return n
|
||
|
}
|
||
|
|
||
|
func InsertSorted[T cmp.Ordered](ts []T, t T) []T {
|
||
|
i, _ := slices.BinarySearch(ts, t)
|
||
|
return slices.Insert(ts, i, t)
|
||
|
}
|