From 8d43e37df99f280377bed90284d6ac2428334804 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Nov 2022 19:55:31 -0500 Subject: move 2021 days to folder; update README --- year2021/day6/consteval.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 year2021/day6/consteval.cpp (limited to 'year2021/day6/consteval.cpp') diff --git a/year2021/day6/consteval.cpp b/year2021/day6/consteval.cpp new file mode 100644 index 0000000..f46da89 --- /dev/null +++ b/year2021/day6/consteval.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +consteval auto countFish(unsigned int day) +{ + unsigned char input[] = { + //3,4,3,1,2 +#include "in" + }; + + uint64_t counts[9]; + std::fill(counts, counts + 9, 0); + for (int i = 0; i < sizeof(input); ++i) + ++counts[input[i]]; + + for (int i = 0; i < day; ++i) { + std::rotate(counts, counts + 1, counts + 9); + counts[6] += counts[8]; + } + + return std::accumulate(counts, counts + 9, 0ull); +} + +int main() +{ + std::cout << "80: " << countFish(80) << std::endl; + std::cout << "256: " << countFish(256) << std::endl; + return 0; +} + -- cgit v1.2.3