package one import ( "strings" ) type kind int const ( kindOfLock kind = iota kindOfKey ) type schematic struct { kind kind heights []int data []string } func newSchematic(buf [][]byte) *schematic { var kind kind data := make([]string, len(buf)) heights := make([]int, len(buf[0])) for i, line := range buf { data[i] = string(line) if i == 0 { switch { case allInString(data[i], '#'): kind = kindOfLock case allInString(data[i], '.'): kind = kindOfKey } } if (kind == kindOfLock && i == 0) || (kind == kindOfKey && 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") }