Skip to content

Commit

Permalink
cleaner still
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Dec 9, 2024
1 parent b63cff3 commit 5c5eb13
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions 2024/src/day9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ long long part2(const Data &data)

auto left = diskmap.begin();
auto right = --diskmap.end();
while(right->first == -1) {
--right;
}
while (right != diskmap.begin()) {
while(left->first != -1 && left != right) {
++left;
}
while(right->first == -1 && left != right) {
--right;
}
if (left == right) {
left = diskmap.begin();
--right;
Expand Down Expand Up @@ -137,25 +137,9 @@ long long part2(const Data &data)

// the block at the end is now unallocated
right->first = -1;
--right;
while(right->first == -1 || moved.contains(right->first)) {
--right;
if (right == diskmap.begin()) break;
}
if (right == diskmap.begin()) break;
}
else {
++left;
if (left == right) {
left = diskmap.begin();
--right;
while(right->first == -1 || moved.contains(right->first)) {
--right;
if (right == diskmap.begin()) break;
}
if (right == diskmap.begin()) break;
continue;
}
++left;
}
// print(diskmap);
}
Expand Down

0 comments on commit 5c5eb13

Please sign in to comment.