diff options
Diffstat (limited to '2024/09/day09a.cpp')
| -rw-r--r-- | 2024/09/day09a.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/2024/09/day09a.cpp b/2024/09/day09a.cpp index c52c8f0..80732d7 100644 --- a/2024/09/day09a.cpp +++ b/2024/09/day09a.cpp | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #include <algorithm> | 1 | #include <algorithm> |
| 2 | #include <iostream> | 2 | #include <iostream> |
| 3 | #include <map> | 3 | #include <map> |
| 4 | #include <ranges> | ||
| 4 | #include <set> | 5 | #include <set> |
| 5 | #include <sstream> | 6 | #include <sstream> |
| 6 | #include <string> | 7 | #include <string> |
| @@ -16,11 +17,11 @@ int main() { | |||
| 16 | a.push_back(id % 2 == 0 ? id/2 : -1); // -1 = space | 17 | a.push_back(id % 2 == 0 ? id/2 : -1); // -1 = space |
| 17 | 18 | ||
| 18 | int j = 0; | 19 | int j = 0; |
| 19 | for (int i = a.size()-1; i >= 0; i--) { | 20 | for (auto& x : a | views::reverse) { |
| 20 | while (a[j] >= 0) j++; | 21 | while (a[j] >= 0) j++; |
| 21 | if (a[j] == -2) break; | 22 | if (a[j] == -2) break; |
| 22 | a[j] = a[i]; | 23 | a[j] = x; |
| 23 | a[i] = -2; // -2 = freed up | 24 | x = -2; // -2 = freed up |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | long long checksum = 0; | 27 | long long checksum = 0; |
