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