mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +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() {
|
for scanner.Scan() {
|
||||||
nums := util.IntsFromString(scanner.Text())
|
nums := util.IntsFromString(scanner.Text())
|
||||||
|
|
||||||
cmpIncrease := func(nums []int, i int) bool {
|
if check(nums, util.CmpIncrease) || check(nums, util.CmpDecrease) {
|
||||||
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) {
|
|
||||||
sum++
|
sum++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,7 @@ func parseLines(r io.Reader) int {
|
|||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
nums := util.IntsFromString(scanner.Text())
|
nums := util.IntsFromString(scanner.Text())
|
||||||
|
|
||||||
cmpIncrease := func(nums []int, i int) bool {
|
if check(withDampener, nums, util.CmpIncrease) || check(withDampener, nums, util.CmpDecrease) {
|
||||||
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) {
|
|
||||||
sum++
|
sum++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,3 +20,11 @@ func IntsFromString(s string) []int {
|
|||||||
}
|
}
|
||||||
return nums
|
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