mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 22:30:47 +00:00
54 lines
798 B
Go
54 lines
798 B
Go
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")
|
|
}
|