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