mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
return scanner errors
This commit is contained in:
parent
417266c838
commit
64f4df4fea
@ -12,12 +12,15 @@ type comparator func([]int, int) bool
|
||||
|
||||
func Solve(data []byte) (int, error) {
|
||||
r := bytes.NewReader(data)
|
||||
sum := parseLines(r)
|
||||
sum, err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) int {
|
||||
func parseLines(r io.Reader) (int, error) {
|
||||
var sum int
|
||||
|
||||
scanner := bufio.NewScanner(r)
|
||||
@ -29,5 +32,9 @@ func parseLines(r io.Reader) int {
|
||||
}
|
||||
}
|
||||
|
||||
return sum
|
||||
if err := scanner.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return sum, nil
|
||||
}
|
||||
|
@ -13,12 +13,15 @@ type dampener func([]int, comparator, int) bool
|
||||
|
||||
func Solve(data []byte) (int, error) {
|
||||
r := bytes.NewReader(data)
|
||||
sum := parseLines(r)
|
||||
sum, err := parseLines(r)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func parseLines(r io.Reader) int {
|
||||
func parseLines(r io.Reader) (int, error) {
|
||||
var sum int
|
||||
|
||||
scanner := bufio.NewScanner(r)
|
||||
@ -30,7 +33,11 @@ func parseLines(r io.Reader) int {
|
||||
}
|
||||
}
|
||||
|
||||
return sum
|
||||
if err := scanner.Err(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return sum, nil
|
||||
}
|
||||
|
||||
func check(fn dampener, nums []int, cmp comparator) bool {
|
||||
|
Loading…
Reference in New Issue
Block a user