aoc2024/day-25/internal/one/util.go

31 lines
625 B
Go
Raw Permalink Normal View History

2024-12-26 19:00:37 +00:00
package one
import (
"bytes"
"io"
)
func parseLines(r io.Reader) (int, map[kind][]*schematic, error) {
2024-12-26 19:00:37 +00:00
raw, _ := io.ReadAll(r)
rawSchematics := bytes.Split(raw, []byte("\n\n"))
schematics := map[kind][]*schematic{kindOfLock: {}, kindOfKey: {}}
2024-12-26 19:00:37 +00:00
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)
2024-12-26 19:00:37 +00:00
return maxHeight, schematics, nil
}
func allInString(s string, r rune) bool {
for _, c := range s {
if c != r {
return false
}
}
return true
}