aoc2024/day-22/internal/one/util.go

32 lines
447 B
Go
Raw Normal View History

2024-12-22 16:54:03 +00:00
package one
import (
"bufio"
"io"
"strconv"
"strings"
)
func parseLines(r io.Reader) ([]int, error) {
secrets := []int{}
scanner := bufio.NewScanner(r)
for scanner.Scan() {
secrets = append(secrets, mustConv(strings.TrimSpace(scanner.Text())))
}
if err := scanner.Err(); err != nil {
return nil, err
}
return secrets, nil
}
func mustConv(s string) int {
n, err := strconv.Atoi(s)
if err != nil {
panic(err)
}
return n
}