summary refs log tree commit diff
path: root/22.5/main.cpp
diff options
context:
space:
mode:
authordzwdz2022-12-05 06:33:34 +0100
committerdzwdz2022-12-05 06:33:34 +0100
commitf3a189826ac3d8bc69ea5c512e846ecb64b2069e (patch)
tree0bb080167fa8bfb0a00881cb39fd9c039a3a24c0 /22.5/main.cpp
parentb6bdf02ea469d71c26cd4d5e14b9dec122070a6b (diff)
day 5: a painfull attemt to get onto the leaderboards
i did part 2 first lmao
Diffstat (limited to '22.5/main.cpp')
-rw-r--r--22.5/main.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/22.5/main.cpp b/22.5/main.cpp
new file mode 100644
index 0000000..b3bc1e8
--- /dev/null
+++ b/22.5/main.cpp
@@ -0,0 +1,54 @@
+#include <cstdio>
+#include <iostream>
+#include <string>
+#include <vector>
+#include <deque>
+using namespace std;
+
+int
+main()
+{
+	string line;
+	vector<deque<char>> crates;
+	while (getline(cin, line)) {
+		if (line.size() < 2) continue;
+		if (line[1] == '1') break;
+
+		int clen = (line.size() + 1) / 4;
+		while (crates.size() < clen)
+			crates.emplace_back();
+		for (int i = 0; i < clen; i++) {
+			int b = i * 4;
+			if (line[b] == '[') {
+				crates[i].push_front(line[b+1]);
+			}
+		}
+		cout << line << endl;
+	}
+	for (auto &s : crates) {
+		for (char c : s)
+			cout << c;
+		cout << endl;
+	}
+	int c, from, to;
+	while (scanf(" move %d from %d to %d", &c, &from, &to) == 3) {
+		from--; to--;
+		int fp = crates[from].size() - c;
+		printf("%d %d>%d %d\n", c, from, to, fp);
+		if (0) { // part 1
+			while(c--) {
+				crates[to].push_back(crates[from].back());
+				crates[from].pop_back();
+			}
+		} else {
+			if (fp < 0) fp = crates[from].size();
+			for (int i = 0; i < c; i++)
+				crates[to].push_back(crates[from][fp + i]);
+			crates[from].erase(crates[from].begin() + fp, crates[from].end());
+		}
+	}
+	for (auto &s : crates) {
+		cout << s.back();
+	}
+	cout << endl;
+}