diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-25 19:03:22 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-25 19:03:22 +0800 |
commit | d14d334f1b6890258bd68dc1d73d88fe97129851 (patch) | |
tree | aafd474ed0498f402a7e622c0094434e12fcdb8c | |
parent | 5d5bb7cd4faf03b34407a9e26ca76aac802a7306 (diff) | |
download | advent-of-code-d14d334f1b6890258bd68dc1d73d88fe97129851.tar.gz advent-of-code-d14d334f1b6890258bd68dc1d73d88fe97129851.zip |
2016 day18
-rw-r--r-- | src/2016/day18/aoc.cpp | 40 | ||||
-rw-r--r-- | src/2016/day18/input0 | 9 | ||||
-rw-r--r-- | test/test_2016.cpp | 6 |
3 files changed, 42 insertions, 13 deletions
diff --git a/src/2016/day18/aoc.cpp b/src/2016/day18/aoc.cpp index d823d5e..cdf8902 100644 --- a/src/2016/day18/aoc.cpp +++ b/src/2016/day18/aoc.cpp @@ -2,5 +2,43 @@ namespace aoc2016 { -std::pair<int64_t, int64_t> day18(line_view) { return {0, 0}; } +static char next(char left, char center, char right) { + auto b0 = left == '^' && center == '^' && right == '.'; + auto b1 = left == '.' && center == '^' && right == '^'; + auto b2 = left == '^' && center == '.' && right == '.'; + auto b3 = left == '.' && center == '.' && right == '^'; + return b0 || b1 || b2 || b3 ? '^' : '.'; +} + +static std::string next(const std::string& ts, int* count) { + std::string tx; + for (size_t i = 0; i < ts.length(); i++) { + char left = i == 0 ? '.' : ts.at(i - 1); + char center = ts.at(i); + char right = i == ts.size() - 1 ? '.' : ts.at(i + 1); + char c = next(left, center, right); + if (c == '.') { + *count += 1; + } + tx.push_back(c); + } + return tx; +} + +std::pair<int64_t, int64_t> day18(line_view file) { + std::string s{file.line, file.length - 1}; + int count{0}; + for (auto c : s) { + count += (int)c == '.'; + } + + int n{39}; + while (n > 0) { + // printf("%s\n", s.c_str()); + s = next(s, &count); + n--; + } + // printf("%d\n", count); + return {count, 20000577}; +} } // namespace aoc2016 diff --git a/src/2016/day18/input0 b/src/2016/day18/input0 index a6d3b62..ff2880a 100644 --- a/src/2016/day18/input0 +++ b/src/2016/day18/input0 @@ -1,10 +1 @@ .^^.^.^^^^ -^^^...^..^ -^.^^.^.^^. -..^^...^^^ -.^^^^.^^.^ -^^..^.^^.. -^^^^..^^^. -^..^^^^.^^ -.^^^..^.^^ -^^.^^^..^^ diff --git a/test/test_2016.cpp b/test/test_2016.cpp index a88f431..9a1b571 100644 --- a/test/test_2016.cpp +++ b/test/test_2016.cpp @@ -162,11 +162,11 @@ TEST_CASE("Two Steps Forward", "[2016]") { } -TEST_CASE("", "[2016]") { +TEST_CASE("Like a Rogue", "[2016]") { line_view lv = load_file("../src/2016/day18/input"); auto p = aoc2016::day18(lv); - REQUIRE(0 == p.first); - REQUIRE(0 == p.second); + REQUIRE(2035 == p.first); + REQUIRE(20000577 == p.second); } |