diff options
Diffstat (limited to 'src/2016/day22/aoc.cpp')
-rw-r--r-- | src/2016/day22/aoc.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/2016/day22/aoc.cpp b/src/2016/day22/aoc.cpp index f115778..b4201e3 100644 --- a/src/2016/day22/aoc.cpp +++ b/src/2016/day22/aoc.cpp @@ -1,6 +1,43 @@ #include "aoc.h" +#include <algorithm> namespace aoc2016 { -std::pair<int64_t, int64_t> day22(line_view) { return {0, 0}; } +// A, B +bool is_pair(const grid_node& n1, const grid_node& n2) { return n1.s[1] > 0 && n2.s[2] >= n1.s[1]; } + +void find_pairs(size_t x, const std::vector<grid_node>& ns, int* count) { + if (x < ns.size() - 1) { + auto& n1 = ns[x]; + for (size_t i = x + 1; i < ns.size(); i++) { + auto& n2 = ns[i]; + if (is_pair(n1, n2)) { + *count += 1; + } + if (is_pair(n2, n1)) { + *count += 1; + } + } + find_pairs(x + 1, ns, count); + } +} + +std::pair<int64_t, int64_t> day22(line_view file) { + std::vector<grid_node> ns; + + per_line(file, [&ns](line_view lv) { + if (*lv.line == '/') { + ns.emplace_back(lv); + } + return true; + }); + + // std::sort(ns.begin(), ns.end()); + // for (auto& n : ns) { + // n.print(); + // } + int count{0}; + find_pairs(0, ns, &count); + return {count, 0}; +} } // namespace aoc2016 |