aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2021-12-06 12:41:51 -0500
committerClyne Sullivan <clyne@bitgloo.com>2021-12-06 12:41:51 -0500
commit4db3315d89be076e7182787a4a098d244690949e (patch)
tree5d1ee3c58e208fa6ab237571be376893f1cf4794
parent6a9feffb4fb6aa2d3483ba7256a243be8df4c952 (diff)
day6: c++ consteval solution
-rw-r--r--day6/consteval.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/day6/consteval.cpp b/day6/consteval.cpp
new file mode 100644
index 0000000..f46da89
--- /dev/null
+++ b/day6/consteval.cpp
@@ -0,0 +1,32 @@
+#include <algorithm>
+#include <cstdint>
+#include <numeric>
+#include <iostream>
+
+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;
+}
+