aoc2024/day-02/internal/one/check.go

17 lines
284 B
Go
Raw Normal View History

2024-12-02 19:28:55 +00:00
package one
import "math"
func check(nums []int, comparator comparator) bool {
2024-12-02 19:28:55 +00:00
for i := 1; i < len(nums); i++ {
if comparator(nums, i) || !isSafe(nums[i-1], nums[i]) {
return false
}
}
return true
}
func isSafe(m, n int) bool {
return int(math.Abs(float64(m-n))) <= 3
}