diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2022/day16/aoc.cpp | 53 | ||||
-rw-r--r-- | src/2022/day17/README.md | 0 | ||||
-rw-r--r-- | src/2022/day17/aoc.cpp | 9 | ||||
-rw-r--r-- | src/2022/day17/aoc.h | 7 | ||||
-rw-r--r-- | src/2022/day17/input | 0 | ||||
-rw-r--r-- | src/2022/day17/input0 | 0 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 |
7 files changed, 46 insertions, 24 deletions
diff --git a/src/2022/day16/aoc.cpp b/src/2022/day16/aoc.cpp index 68213e8..17fd268 100644 --- a/src/2022/day16/aoc.cpp +++ b/src/2022/day16/aoc.cpp @@ -1,6 +1,7 @@ #include "aoc.h" #include <algorithm> #include <iostream> +#include <set> #include <vector> namespace aoc2022 { @@ -12,43 +13,41 @@ static valve* get(line_view lv) { return p.first->second; } -std::pair<int, size_t> get_opened() { +std::pair<int, size_t> get_opened(std::set<valve*>& opened) { int total{0}; size_t n{0}; - for (auto& kv : valves) { - if (kv.second->open) { - total += kv.second->rate; - n += 1; - } + for (auto& v : opened) { + total += v->rate; + n += 1; } return {total, n}; } -static char* indent(int s) { - static char space[100] = {0}; - memset(space, 0, 100); - for (int i = 0; i < s; i++) { - space[i] = ' '; - } - return space; -} +// static char* indent(int s) { +// static char space[100] = {0}; +// memset(space, 0, 100); +// for (int i = 0; i < s; i++) { +// space[i] = ' '; +// } +// return space; +// } -void flow(int minute, valve* v, int total, int* maxtotal) { - auto p = get_opened(); +void flow(int minute, valve* v, std::set<valve*>& opened, int total, int* maxtotal) { + auto p = get_opened(opened); total += p.first; - std::cout << indent(minute) << v->name; - printf(": %d %zu %d\n", p.first, p.second, total); + // std::cout << indent(minute) << v->name; + // printf(": %d %zu %d\n", p.first, p.second, total); if (minute >= 30) { if (total > *maxtotal) { *maxtotal = total; } } else { if (p.second == maxopened) { - flow(minute + 1, v, total, maxtotal); + flow(minute + 1, v, opened, total, maxtotal); } else { if (v->rate == 0 || v->open) { for (auto& o : v->others) { - flow(minute + 1, get(o), total, maxtotal); + flow(minute + 1, get(o), opened, total, maxtotal); } } else { // v-rate > 0 && v->open == false auto others = v->others; @@ -56,9 +55,13 @@ void flow(int minute, valve* v, int total, int* maxtotal) { for (auto& o : others) { if (o == v->name) { // choose open get(o)->open = true; - minute += 1; + opened.insert(v); + flow(minute + 2, get(o), opened, total, maxtotal); + } + else { + auto os = opened; + flow(minute + 1, get(o), os, total, maxtotal); } - flow(minute + 1, get(o), total, maxtotal); } } } @@ -94,10 +97,12 @@ std::pair<int, int> day16(line_view file) { } int max{0}; - flow(1, get("AA"), 0, &max); + std::set<valve*> opened; + flow(1, get("AA"), opened, 0, &max); for (auto& vm : vs) { - flow(1, vm.v, 0, &vm.max); + std::set<valve*> os; + flow(1, vm.v, os, 0, &vm.max); } std::sort(vs.begin(), vs.end(), [](vmax v1, vmax v2) { return v1.max > v2.max; }); diff --git a/src/2022/day17/README.md b/src/2022/day17/README.md new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/2022/day17/README.md diff --git a/src/2022/day17/aoc.cpp b/src/2022/day17/aoc.cpp new file mode 100644 index 0000000..c35000b --- /dev/null +++ b/src/2022/day17/aoc.cpp @@ -0,0 +1,9 @@ +#include "aoc.h" + +namespace aoc2022 { + +std::pair<int, int> day17(line_view) { + return {0, 0}; +} +} + diff --git a/src/2022/day17/aoc.h b/src/2022/day17/aoc.h new file mode 100644 index 0000000..d60e69a --- /dev/null +++ b/src/2022/day17/aoc.h @@ -0,0 +1,7 @@ +#include "common.h" +#include <vector> + +namespace aoc2022 { + +std::pair<int, int> day17(line_view); +} diff --git a/src/2022/day17/input b/src/2022/day17/input new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/2022/day17/input diff --git a/src/2022/day17/input0 b/src/2022/day17/input0 new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/2022/day17/input0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e17647..5b9c91a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,6 +101,7 @@ set(SOLUTION_FILES "2022/day14/aoc.cpp" "2022/day15/aoc.cpp" "2022/day16/aoc.cpp" + "2022/day17/aoc.cpp" ) add_library(solution SHARED ${SOLUTION_FILES}) |