aoc2024/day-09/internal/one/disk.go
2024-12-19 12:54:40 +00:00

25 lines
327 B
Go

package one
import "slices"
type disk struct {
data []int
}
func newDisk(raw []int) *disk {
return &disk{
data: raw,
}
}
func (d *disk) reorganise() {
for i := len(d.data) - 1; i >= 0; i-- {
indx := slices.Index(d.data, empty)
if indx >= i {
break
}
d.data[i], d.data[indx] = d.data[indx], d.data[i]
}
}