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 }