mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-10 14:50:46 +00:00
28 lines
375 B
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
|
|
}
|