diff options
Diffstat (limited to 'src/2022/day23/aoc.cpp')
-rw-r--r-- | src/2022/day23/aoc.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/2022/day23/aoc.cpp b/src/2022/day23/aoc.cpp index 8b9d091..1b5a9e6 100644 --- a/src/2022/day23/aoc.cpp +++ b/src/2022/day23/aoc.cpp @@ -81,21 +81,19 @@ bool east_three(elf e, const std::set<elf>& elves) { return true; } -struct elf_test { +static struct elf_test { elf_predicate p; elf_move m; -} moves[4] = {{north_three, north}, {south_three, south}, {west_three, west}, {east_three, east}}; +} moves[5] = {{eight, nomove}, {north_three, north}, {south_three, south}, {west_three, west}, {east_three, east}}; std::vector<elf> round(int i, const std::vector<elf>& elfs, const std::set<elf>& elves) { std::vector<elf> next; - elf_test top{eight, nomove}; for (auto& e : elfs) { - if (top.p(e, elves)) { - next.emplace_back(top.m(e)); - } - else { + if (moves[0].p(e, elves)) { + next.emplace_back(moves[0].m(e)); + } else { for (int x = 0; x < 4; x++) { - int index = (i + x) % 4; + int index = (i + x) % 4 + 1; if (moves[index].p(e, elves)) { next.emplace_back(moves[index].m(e)); break; @@ -115,7 +113,7 @@ std::pair<int, int> day23(line_view file) { per_line(file, [&height, &elfs](line_view lv) { for (size_t i = 0; i < lv.length; i++) { if (*(lv.line + i) == '#') { - elfs.emplace_back(elf{(int) i, height}); + elfs.emplace_back(elf{(int)i, height}); } } height++; |