mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
17 lines
298 B
Go
17 lines
298 B
Go
|
package one
|
||
|
|
||
|
import "math"
|
||
|
|
||
|
func checkWithComparator(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
|
||
|
}
|