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

32 lines
452 B
Go
Raw Normal View History

2024-12-10 21:42:26 +00:00
package two
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)
log.Debug(disk.debug())
disk.sort()
log.Debug(disk.debug())
var checksum int
for i := 0; i < len(disk.data); i++ {
if disk.data[i] == empty {
continue
}
checksum += i * disk.data[i]
}
return checksum, nil
}