mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
36 lines
493 B
Go
36 lines
493 B
Go
|
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
|
||
|
}
|