2024-12-26 19:00:37 +00:00
|
|
|
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
|
2024-12-27 00:39:46 +00:00
|
|
|
for _, lock := range schematics[kindOfLock] {
|
|
|
|
for _, key := range schematics[kindOfKey] {
|
2024-12-26 19:00:37 +00:00
|
|
|
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
|
|
|
|
}
|