mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
17 lines
270 B
Go
17 lines
270 B
Go
package one
|
|
|
|
import "math"
|
|
|
|
func check(nums []int, cmp comparator) bool {
|
|
for i := 1; i < len(nums); i++ {
|
|
if cmp(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
|
|
}
|