package two import ( "bufio" "bytes" "io" "github.com/onyx-and-iris/aoc2024/day-02/internal/util" ) type comparator func([]int, int) bool type dampener func([]int, comparator, int) bool func Solve(data []byte) (int, error) { r := bytes.NewReader(data) sum := parseLines(r) return sum, nil } func parseLines(r io.Reader) int { var sum int scanner := bufio.NewScanner(r) for scanner.Scan() { nums := util.IntsFromString(scanner.Text()) if check(withDampener, nums, util.CmpIncrease) || check(withDampener, nums, util.CmpDecrease) { sum++ } } return sum } func check(fn dampener, nums []int, cmp comparator) bool { var count int return fn(nums, cmp, count) }