move comparator functions into util

This commit is contained in:
onyx-and-iris 2024-12-02 22:48:19 +00:00
parent 4416dab080
commit 417266c838
3 changed files with 10 additions and 16 deletions

View File

@ -24,14 +24,7 @@ func parseLines(r io.Reader) int {
for scanner.Scan() {
nums := util.IntsFromString(scanner.Text())
cmpIncrease := func(nums []int, i int) bool {
return nums[i-1] >= nums[i]
}
cmpDecrease := func(nums []int, i int) bool {
return nums[i-1] <= nums[i]
}
if check(nums, cmpIncrease) || check(nums, cmpDecrease) {
if check(nums, util.CmpIncrease) || check(nums, util.CmpDecrease) {
sum++
}
}

View File

@ -25,14 +25,7 @@ func parseLines(r io.Reader) int {
for scanner.Scan() {
nums := util.IntsFromString(scanner.Text())
cmpIncrease := func(nums []int, i int) bool {
return nums[i-1] >= nums[i]
}
cmpDecrease := func(nums []int, i int) bool {
return nums[i-1] <= nums[i]
}
if check(withDampener, nums, cmpIncrease) || check(withDampener, nums, cmpDecrease) {
if check(withDampener, nums, util.CmpIncrease) || check(withDampener, nums, util.CmpDecrease) {
sum++
}
}

View File

@ -20,3 +20,11 @@ func IntsFromString(s string) []int {
}
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]
}