package one import ( "bufio" "bytes" "io" ) type comparator func([]int, int) bool func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) sum, err := parseLines(r) if err != nil { return 0, err } return sum, nil } func parseLines(r io.Reader) (int, error) { var ( 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] } ) var sum int scanner := bufio.NewScanner(r) for scanner.Scan() { nums := intsFromString(scanner.Text()) if check(nums, cmpIncrease) || check(nums, cmpDecrease) { sum++ } } if err := scanner.Err(); err != nil { return 0, err } return sum, nil }