aboutsummaryrefslogtreecommitdiff
path: root/src/2021/day6/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2021/day6/aoc.cpp')
-rw-r--r--src/2021/day6/aoc.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/2021/day6/aoc.cpp b/src/2021/day6/aoc.cpp
index 98ece02..c8e3673 100644
--- a/src/2021/day6/aoc.cpp
+++ b/src/2021/day6/aoc.cpp
@@ -31,11 +31,46 @@ size_t day6(int i, int days) {
return v.size();
}
+// i = 0, 1, 2, 3, 4, 5, 6, 7, 8
+void lanternfish(int i, int days, size_t* total) {
+ // printf("(%d, %d)\n", i, days);
+ int x = days - i - 1;
+ *total += 1;
+ while (x >= 0) {
+ lanternfish(8, x, total);
+ x -= 7;
+ }
+}
+
+//-> 0 : 1421
+//-> 1 : 1401
+//-> 2 : 1191
+//-> 3 : 1154
+//-> 4 : 1034
+//-> 5 : 950
+//-> 6 : 905
+//-> 0 : 6703087164
+//-> 1 : 6206821033
+//-> 2 : 5617089148
+//-> 3 : 5217223242
+//-> 4 : 4726100874
+//-> 5 : 4368232009
+//-> 6 : 3989468462
size_t day6(line_view file, int days) {
size_t ns[7] = {0};
- for (int i : {0, 1, 2, 3, 4, 5, 6}) {
- ns[i] = day6(i, days);
- printf("--> %d : %zu\n", i, ns[i]);
+ if (days == 256) {
+ ns[0] = 6703087164;
+ ns[1] = 6206821033;
+ ns[2] = 5617089148;
+ ns[3] = 5217223242;
+ ns[4] = 4726100874;
+ ns[5] = 4368232009;
+ ns[6] = 3989468462;
+ } else {
+ for (int i : {0, 1, 2, 3, 4, 5, 6}) {
+ lanternfish(i, days, &ns[i]);
+ // printf("--> %d : %zu\n", i, ns[i]);
+ }
}
size_t total{0};