diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-02-14 17:15:01 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-02-14 17:15:01 +0800 |
commit | 5929a590f15cb0d6aeccb6940db0e2d2999a676f (patch) | |
tree | 734d1595adcce1b20295c81c5e949cc95ebaddf6 | |
parent | 4c6da7a0f332d14c1f11c9427259e871c03cac50 (diff) | |
download | advent-of-code-5929a590f15cb0d6aeccb6940db0e2d2999a676f.tar.gz advent-of-code-5929a590f15cb0d6aeccb6940db0e2d2999a676f.zip |
2017 day21 part1
-rw-r--r-- | src/2017/day21/aoc.cpp | 18 | ||||
-rw-r--r-- | src/2017/day21/aoc.h | 16 |
2 files changed, 33 insertions, 1 deletions
diff --git a/src/2017/day21/aoc.cpp b/src/2017/day21/aoc.cpp index 716d4e6..b1f315a 100644 --- a/src/2017/day21/aoc.cpp +++ b/src/2017/day21/aoc.cpp @@ -3,6 +3,20 @@ namespace aoc2017 { +typedef void (*sfunc)(std::vector<square3>* vs3, std::vector<square2>* vs2, + const std::map<std::string, std::string>& rs); +void s3tos2(std::vector<square3>* vs3, std::vector<square2>* vs2, const std::map<std::string, std::string>& rs) {} +void s2tos3(std::vector<square3>* vs3, std::vector<square2>* vs2, const std::map<std::string, std::string>& rs) {} + +static void part1(int t, int times, std::vector<square3>* vs3, std::vector<square2>* vs2, + const std::map<std::string, std::string>& rs) { + sfunc fs[2] = {s3tos2, s2tos3}; + if (t <= times) { + sfunc f = fs[t % 2]; + f(vs3, vs2, rs); + } +} + std::pair<int64_t, int64_t> day21(line_view file) { std::map<std::string, std::string> rules; @@ -28,7 +42,9 @@ std::pair<int64_t, int64_t> day21(line_view file) { // .#. // ..# // ### - square3 s3{".#./..#/###"}; + std::vector<square3> vs3{{".#./..#/###"}}; + std::vector<square2> vs2; + part1(1, 5, &vs3, &vs2, rules); // for (auto& kv : rules) { // printf("%s => %s\n", kv.first.c_str(), kv.second.c_str()); diff --git a/src/2017/day21/aoc.h b/src/2017/day21/aoc.h index 1ee9711..c2bae44 100644 --- a/src/2017/day21/aoc.h +++ b/src/2017/day21/aoc.h @@ -62,6 +62,14 @@ struct square2 { return sx; } + int count() const noexcept { + int c{0}; + for (int i = 0; i < 4; i++) { + c += (int)s[i] == '#'; + } + return c; + } + void print() const noexcept { for (int i = 0; i < 4; i++) { printf("%c", s[i]); @@ -198,6 +206,14 @@ struct square3 { return sx; } + int count() const noexcept { + int c{0}; + for (int i = 0; i < 9; i++) { + c += (int)s[i] == '#'; + } + return c; + } + void print() const noexcept { for (int i = 0; i < 9; i++) { printf("%c", s[i]); |