aoc2024/day-25/internal/one/schematic.go
2024-12-26 19:00:37 +00:00

56 lines
815 B
Go

package one
import (
"strings"
)
type kindOfSchematic int
const (
Lock kindOfSchematic = iota
Key
)
type schematic struct {
kind kindOfSchematic
heights []int
data []string
}
func newSchematic(buf [][]byte) *schematic {
var kind kindOfSchematic
data := make([]string, len(buf))
heights := make([]int, len(buf[0]))
for i, line := range buf {
data[i] = string(line)
if i == 0 {
if allInString(data[i], '#') {
kind = Lock
} else if allInString(data[i], '.') {
kind = Key
}
}
if kind == Lock && i == 0 {
continue
}
if kind == Key && i == len(buf)-1 {
continue
}
for j, r := range data[i] {
if r == '#' {
heights[j]++
}
}
}
return &schematic{kind, heights, data}
}
func (s *schematic) String() string {
return strings.Join(s.data, "\n")
}