mirror of
https://github.com/onyx-and-iris/aoc2024.git
synced 2025-01-09 14:20:48 +00:00
25 lines
327 B
Go
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]
|
|
}
|
|
}
|