mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 06:10:47 +00:00
29 lines
367 B
Go
29 lines
367 B
Go
package one
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
const empty = -1
|
|
|
|
func Solve(buf []byte) (int, error) {
|
|
r := bytes.NewReader(buf)
|
|
expandedRaw, err := parseLines(r)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
disk := newDisk(expandedRaw)
|
|
disk.reorganise()
|
|
|
|
var checksum int
|
|
for i, n := range disk.data {
|
|
if n == empty {
|
|
break
|
|
}
|
|
checksum += i * n
|
|
}
|
|
|
|
return checksum, nil
|
|
}
|