From 9a1f073f8e33e8b0d6c97332f51161683cfc6e58 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 9 Dec 2024 14:06:37 +0100 Subject: Day 9 with views::reverse --- 2024/09/day09a.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to '2024/09/day09a.cpp') 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 @@ #include #include #include +#include #include #include #include @@ -16,11 +17,11 @@ int main() { a.push_back(id % 2 == 0 ? id/2 : -1); // -1 = space int j = 0; - for (int i = a.size()-1; i >= 0; i--) { + for (auto& x : a | views::reverse) { while (a[j] >= 0) j++; if (a[j] == -2) break; - a[j] = a[i]; - a[i] = -2; // -2 = freed up + a[j] = x; + x = -2; // -2 = freed up } long long checksum = 0; -- cgit v1.3