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

36 lines
493 B
Go
Raw Permalink Normal View History

2024-12-22 16:54:03 +00:00
package two
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
}
func lastDigit(n int) int {
return n % 10
}