From 91d9f6e34065ebd993c420ae998c0992d8a5a12c Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Tue, 15 Nov 2022 21:35:20 -0800 Subject: [PATCH] cleanup --- 2019/16.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/2019/16.cpp b/2019/16.cpp index 30634a5..598fd0b 100644 --- a/2019/16.cpp +++ b/2019/16.cpp @@ -8,12 +8,12 @@ using namespace aocpp; namespace { -auto FFT(std::size_t start, std::vector const& prev) +auto FFT(std::size_t const start, std::vector const& prev) { std::vector result; std::vector partial_sums; auto n = prev.size(); - result.resize(n); + result.reserve(n); partial_sums.reserve(n+1); partial_sums.push_back(0); @@ -22,14 +22,14 @@ auto FFT(std::size_t start, std::vector const& prev) partial_sums.push_back(acc += x); } - for (std::size_t i = start; i < n+start; i++) { + for (std::size_t i = 0; i < n; i++) { std::int32_t acc = 0; - for (std::size_t offset = i; offset < n+start; offset += 4*(i+1)) { - acc += partial_sums[std::min(n,offset-start + i + 1)] - partial_sums[std::min(n, offset-start)]; - acc -= partial_sums[std::min(n, offset-start + 3*(i + 1))] - partial_sums[std::min(n, offset-start + 2*(i + 1))]; + auto step = i+start+1; + for (std::size_t offset = i; offset < n; offset += 4*step) { + acc += partial_sums[std::min(n, offset + 1*step)] - partial_sums[std::min(n, offset )]; + acc -= partial_sums[std::min(n, offset + 3*step)] - partial_sums[std::min(n, offset + 2*step)]; } - - result[i-start] = std::abs(acc % 10); + result.push_back(std::abs(acc % 10)); } return result; }