Move code out of cmd

This commit is contained in:
2025-12-03 23:03:27 +02:00
parent 1d458af093
commit 8257e0a02f
15 changed files with 0 additions and 0 deletions

22
day3/battery.go Normal file
View 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()
}