diff --git a/day-09/internal/two/disk.go b/day-09/internal/two/disk.go index 1c52ac8..037b8e1 100644 --- a/day-09/internal/two/disk.go +++ b/day-09/internal/two/disk.go @@ -124,7 +124,7 @@ func (d *disk) write() { allBlocks = append(allBlocks, d.fileblocks...) for i := 0; i < numEmptyBlocks; i++ { - for range d.emptyblocks[i].Len() { + for !d.emptyblocks[i].IsEmpty() { allBlocks = append(allBlocks, heap.Pop(&d.emptyblocks[i]).(*block)) } } diff --git a/day-09/internal/two/heap.go b/day-09/internal/two/heap.go index db5cba8..6e68e37 100644 --- a/day-09/internal/two/heap.go +++ b/day-09/internal/two/heap.go @@ -25,3 +25,7 @@ func (h *minHeap) Pop() interface{} { *h = old[:n-1] return x } + +func (h *minHeap) IsEmpty() bool { + return h.Len() == 0 +}