aoc2024/day-09/internal/one/disk.go

25 lines
327 B
Go
Raw Permalink Normal View History

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