aoc2024/day-09/internal/one/solve.go

28 lines
375 B
Go

package one
import (
"bytes"
log "github.com/sirupsen/logrus"
)
func Solve(buf []byte) (int, error) {
r := bytes.NewReader(buf)
blocks, err := parseLines(r)
if err != nil {
return 0, err
}
disk := newDisk(blocks)
disk.sort()
log.Debug(disk.debug())
var i, checksum int
for range disk.len() {
checksum += i * disk.data[i]
i++
}
return checksum, nil
}