From 829c9aafcea07033c5d4ad73f0928945f9690e48 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Mon, 4 Dec 2023 16:29:48 -0800 Subject: [PATCH] simplify --- 2023/04.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/2023/04.cpp b/2023/04.cpp index 0855b5e..6c6bf35 100644 --- a/2023/04.cpp +++ b/2023/04.cpp @@ -72,11 +72,10 @@ auto Part1(std::vector const& wins) -> std::uint64_t auto Part2(std::vector const& wins) -> std::size_t { - std::vector psums(wins); - psums.push_back(0); + std::vector psums(wins.size() + 1); for (std::size_t i = wins.size(); i --> 0;) { - psums[i] = 1 + 2 * psums[i+1] - psums[1 + i + psums[i]]; + psums[i] = 1 + 2 * psums[i + 1] - psums[i + 1 + wins[i]]; } return psums.front(); }