diff options
author | kaiwu <kaiwu2004@gmail.com> | 2023-01-04 23:00:13 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2023-01-04 23:00:13 +0800 |
commit | b5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d (patch) | |
tree | 4e20218508678f3faea830a30ff107b92ab2585d /src | |
parent | b034ad46b9f950e7934935f6f6f4129a78c2ee09 (diff) | |
download | advent-of-code-b5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d.tar.gz advent-of-code-b5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d.zip |
2022 day23 part1
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}; |