Skip to content

Commit 5c5eb13

Browse files
committed
cleaner still
1 parent b63cff3 commit 5c5eb13

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

2024/src/day9.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ long long part2(const Data &data)
102102

103103
auto left = diskmap.begin();
104104
auto right = --diskmap.end();
105-
while(right->first == -1) {
106-
--right;
107-
}
108105
while (right != diskmap.begin()) {
109106
while(left->first != -1 && left != right) {
110107
++left;
111108
}
109+
while(right->first == -1 && left != right) {
110+
--right;
111+
}
112112
if (left == right) {
113113
left = diskmap.begin();
114114
--right;
@@ -137,25 +137,9 @@ long long part2(const Data &data)
137137

138138
// the block at the end is now unallocated
139139
right->first = -1;
140-
--right;
141-
while(right->first == -1 || moved.contains(right->first)) {
142-
--right;
143-
if (right == diskmap.begin()) break;
144-
}
145-
if (right == diskmap.begin()) break;
146140
}
147141
else {
148-
++left;
149-
if (left == right) {
150-
left = diskmap.begin();
151-
--right;
152-
while(right->first == -1 || moved.contains(right->first)) {
153-
--right;
154-
if (right == diskmap.begin()) break;
155-
}
156-
if (right == diskmap.begin()) break;
157-
continue;
158-
}
142+
++left;
159143
}
160144
// print(diskmap);
161145
}

0 commit comments

Comments
 (0)