mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 06:40:47 +00:00
17 lines
284 B
Go
17 lines
284 B
Go
package one
|
|
|
|
import "math"
|
|
|
|
func check(nums []int, comparator comparator) bool {
|
|
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
|
|
}
|