aboutsummaryrefslogtreecommitdiff
path: root/src/2020/day5/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-11 18:21:54 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-11 18:21:54 +0800
commit7f2c5f3c2060469a2b334b6ca1276633009d81a9 (patch)
treea14103c46a58b9bec03174ef45f8a460fbe804df /src/2020/day5/aoc.cpp
parentea36af28425c7db302043c93b26af203074c51ec (diff)
downloadadvent-of-code-7f2c5f3c2060469a2b334b6ca1276633009d81a9.tar.gz
advent-of-code-7f2c5f3c2060469a2b334b6ca1276633009d81a9.zip
2020 day5
Diffstat (limited to 'src/2020/day5/aoc.cpp')
-rw-r--r--src/2020/day5/aoc.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/2020/day5/aoc.cpp b/src/2020/day5/aoc.cpp
index 849bad9..2ea306a 100644
--- a/src/2020/day5/aoc.cpp
+++ b/src/2020/day5/aoc.cpp
@@ -1,5 +1,38 @@
#include "aoc.h"
+#include <algorithm>
+#include <vector>
namespace aoc2020 {
+// row 0 - 127
+// col 0 - 7
+static void missing(const std::vector<seat>& seats, std::vector<seat>& miss) {
+ static int plane[128 * 8] = {0};
+ for (auto& s : seats) {
+ plane[8 * s.row + s.col] = 1;
+ }
+ for (size_t i = 0; i < ARRAY_SIZE(plane); i++) {
+ if (plane[i] == 0) {
+ int r = i / 8;
+ int c = i % 8;
+ if (r != 0 && r != 127) {
+ miss.emplace_back(seat{r, c});
+ }
+ }
+ }
}
+
+int day5(line_view file) {
+ std::vector<seat> seats;
+ per_line(file, [&seats](line_view lv) {
+ seats.emplace_back(lv);
+ return true;
+ });
+ std::vector<seat> miss;
+ missing(seats, miss);
+ // std::for_each(miss.begin(), miss.end(), [](const seat& s) { printf("%d %d %d\n", s.row, s.col, s.id()); });
+ std::sort(seats.begin(), seats.end());
+ return seats[seats.size() - 1].id();
+}
+
+} // namespace aoc2020