aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day18/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2016/day18/aoc.cpp')
-rw-r--r--src/2016/day18/aoc.cpp40
1 files changed, 39 insertions, 1 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