mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
move comparator functions into util
This commit is contained in:
parent
4416dab080
commit
417266c838
@ -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++
|
||||
}
|
||||
}
|
||||
|
@ -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++
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user