mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
31 lines
460 B
Go
31 lines
460 B
Go
package util
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func MustConv(s string) int {
|
|
n, err := strconv.Atoi(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func IntsFromString(s string) []int {
|
|
nums := []int{}
|
|
for _, r := range strings.Fields(s) {
|
|
nums = append(nums, MustConv(r))
|
|
}
|
|
return nums
|
|
}
|
|
|
|
var CmpIncrease = func(nums []int, i int) bool {
|
|
return nums[i-1] >= nums[i]
|
|
}
|
|
|
|
var CmpDecrease = func(nums []int, i int) bool {
|
|
return nums[i-1] <= nums[i]
|
|
}
|