about summary refs log tree commit diff
path: root/day19.cc
diff options
context:
space:
mode:
Diffstat (limited to 'day19.cc')
-rw-r--r--day19.cc37
1 files changed, 37 insertions, 0 deletions
diff --git a/day19.cc b/day19.cc
new file mode 100644
index 0000000..79a2c34
--- /dev/null
+++ b/day19.cc
@@ -0,0 +1,37 @@
+#include <string>
+#include <vector>
+#include <iostream>
+
+using namespace std;
+
+int
+main()
+{
+	vector<string> d;
+
+	for (string l; getline(cin, l); )
+		d.push_back(l);
+
+	int y = 0;
+	int x = d[y].find('|');
+
+	string p1;
+	int p2 = 0;
+
+	for (int dx = 0, dy = 1; d[y][x] != ' '; x += dx, y += dy, p2++) {
+		if (isupper(d[y][x]))
+			p1.push_back(d[y][x]);
+
+		if (d[y][x] == '+') {
+			if (dx) {
+				dx = 0;
+				dy = (d[y+1][x] != ' ') ? 1 : -1;
+			} else {
+				dx = (d[y][x+1] != ' ') ? 1 : -1;
+				dy = 0;
+			}
+		}
+	}
+
+	cout << p1 << endl << p2 << endl;
+}