diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-03-15 11:27:38 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-03-15 11:27:38 +0800 |
commit | 6e7699abd4ed70c372477c4d1797dab1b15d131b (patch) | |
tree | 1b005a2a6d3d48577ac46e21a5c5505723ecd730 | |
parent | 010adeb053704218fda2ffb991d0d166c6d632d0 (diff) | |
download | advent-of-code-6e7699abd4ed70c372477c4d1797dab1b15d131b.tar.gz advent-of-code-6e7699abd4ed70c372477c4d1797dab1b15d131b.zip |
2017 day23 part2
-rw-r--r-- | src/2017/day23/aoc.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/2017/day23/aoc.cpp b/src/2017/day23/aoc.cpp index 7d990e3..4d44c24 100644 --- a/src/2017/day23/aoc.cpp +++ b/src/2017/day23/aoc.cpp @@ -81,7 +81,7 @@ static size_t exec(size_t index, const std::vector<line_view>& todos, int64_t rs return index; } -static void part1(const std::vector<line_view>& todos) { +static void part1(std::vector<line_view> todos) { size_t index{0}; int64_t rs[26] = {0}; @@ -90,15 +90,34 @@ static void part1(const std::vector<line_view>& todos) { } } +static void part2(std::vector<line_view> todos) { + size_t index{0}; + int64_t rs[26] = {0}; + rs[0] = 1; // a is 1 + auto print = [](int64_t is[26]) { + for (char c = 'a'; c <= 'h'; c++) { + printf("%c[%ld] ", c, is[c - 'a']); + } + printf("\n"); + }; + + while (index < todos.size()) { + std::cout << todos[index] << " "; + index = exec(index, todos, rs); + print(rs); + } +} + std::pair<int64_t, int64_t> day23(line_view file) { std::vector<line_view> todos; per_line(file, [&todos](line_view lv) { - todos.push_back(lv); + todos.push_back({lv.line, lv.length - 1}); return true; }); part1(todos); int64_t t0 = fs[2].c; + part2(todos); return {t0, 0}; } |