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

35 lines
599 B
Go

package one
import (
"bytes"
log "github.com/sirupsen/logrus"
)
func Solve(buf []byte) (int, error) {
r := bytes.NewReader(buf)
maxHeight, schematics, err := parseLines(r)
if err != nil {
return 0, err
}
var count int
for _, lock := range schematics[kindOfLock] {
for _, key := range schematics[kindOfKey] {
if func() bool {
for i := range key.heights {
if key.heights[i]+lock.heights[i] > maxHeight {
return false
}
}
return true
}() {
count++
log.Debugf("lock: %v and key: %v", lock.heights, key.heights)
}
}
}
return count, nil
}