diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/2022/day23/aoc.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/2022/day23/aoc.cpp b/src/2022/day23/aoc.cpp index 48a2099..8b9d091 100644 --- a/src/2022/day23/aoc.cpp +++ b/src/2022/day23/aoc.cpp @@ -84,7 +84,29 @@ bool east_three(elf e, const std::set<elf>& elves) { struct elf_test { elf_predicate p; elf_move m; -} moves[5] = {{eight, nomove}, {north_three, north}, {south_three, south}, {west_three, west}, {east_three, east}}; +} moves[4] = {{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 { + for (int x = 0; x < 4; x++) { + int index = (i + x) % 4; + if (moves[index].p(e, elves)) { + next.emplace_back(moves[index].m(e)); + break; + } + } + } + } + + // check duplicate of next + return next; +} std::pair<int, int> day23(line_view file) { int height{0}; |