aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2023-01-04 23:00:13 +0800
committerkaiwu <kaiwu2004@gmail.com>2023-01-04 23:00:13 +0800
commitb5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d (patch)
tree4e20218508678f3faea830a30ff107b92ab2585d
parentb034ad46b9f950e7934935f6f6f4129a78c2ee09 (diff)
downloadadvent-of-code-b5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d.tar.gz
advent-of-code-b5cc0b2ac4e37707f30d7d9ae3fa74c790629f9d.zip
2022 day23 part1
-rw-r--r--src/2022/day23/aoc.cpp24
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};