Move code out of cmd
This commit is contained in:
22
day3/battery.go
Normal file
22
day3/battery.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func readBatteries(r io.Reader) (banks [][]uint8, err error) {
|
||||
sc := bufio.NewScanner(r)
|
||||
for sc.Scan() {
|
||||
var bank []uint8
|
||||
for _, b := range sc.Bytes() {
|
||||
if b < '0' || b > '9' {
|
||||
return nil, fmt.Errorf("bank %q: invalid joltage %q", sc.Text(), b)
|
||||
}
|
||||
bank = append(bank, b-'0')
|
||||
}
|
||||
banks = append(banks, bank)
|
||||
}
|
||||
return banks, sc.Err()
|
||||
}
|
||||
Reference in New Issue
Block a user