#include "aoc.h" namespace aoc2016 { 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 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