From 8834ee5feb727f81b90c28882920d732454695eb Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Tue, 17 Dec 2024 21:38:52 -0800 Subject: [PATCH] 2024 day 18 --- 2024/18/main.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 2024/18/main.cpp diff --git a/2024/18/main.cpp b/2024/18/main.cpp new file mode 100644 index 0000000..0bb3566 --- /dev/null +++ b/2024/18/main.cpp @@ -0,0 +1,58 @@ +#include "../../include/aoc.hpp" +#include +using namespace std; + +unordered_map m; +const int smax = 70; + +void rec(icoord c, int score) { + if (!m.contains(c)) { + return; + } + + int &s = m[c]; + if (s != -1 && s <= score) { + return; + } + + s = score; + score++; + + rec(c + icoord(1, 0), score); + rec(c + icoord(-1, 0), score); + rec(c + icoord(0, 1), score); + rec(c + icoord(0, -1), score); +} + +int main() { + ios::sync_with_stdio(0); + cin.tie(0); + + string line; + bool inits[smax + 1][smax + 1] = {}; + int i = 0; + while (getline(cin, line) && !line.empty()) { + // NOTE: found part 2 is just binary search on this number until you + // stop getting -1 as output + if (++i > 1024) { + break; + } + istringstream l(line); + int x, y; + l >> x; + l.ignore(); + l >> y; + inits[x][y] = true; + } + + for (int x = 0; x <= smax; x++) { + for (int y = 0; y <= smax; y++) { + if (!inits[x][y]) { + m[{x, y}] = -1; + } + } + } + + rec({0, 0}, 0); + cout << m[{smax, smax}] << '\n'; +}