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 }