aoc2024/day-25/internal/one/util.go
onyx-and-iris 51fed356af rename kind type/variables
refactor schematic factory function
2024-12-27 00:39:46 +00:00

31 lines
625 B
Go

package one
import (
"bytes"
"io"
)
func parseLines(r io.Reader) (int, map[kind][]*schematic, error) {
raw, _ := io.ReadAll(r)
rawSchematics := bytes.Split(raw, []byte("\n\n"))
schematics := map[kind][]*schematic{kindOfLock: {}, kindOfKey: {}}
for _, rawSchematic := range rawSchematics {
s := newSchematic(bytes.Split(rawSchematic, []byte("\n")))
schematics[s.kind] = append(schematics[s.kind], s)
}
maxHeight := len(schematics[kindOfLock][0].heights)
return maxHeight, schematics, nil
}
func allInString(s string, r rune) bool {
for _, c := range s {
if c != r {
return false
}
}
return true
}