about summary refs log tree commit diff
path: root/day19.cc
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-20 19:31:13 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-20 19:31:13 +0100
commitf6ecf88a2d9da1f140abedc52a0b9b46108a6563 (patch)
treefa336b0f152d821c3e58249b891aee2fc57e88ea /day19.cc
parent868e907bdec033e993e02a6208d6ec6c96402e4f (diff)
downloadadventofcode2017-f6ecf88a2d9da1f140abedc52a0b9b46108a6563.tar.gz
adventofcode2017-f6ecf88a2d9da1f140abedc52a0b9b46108a6563.tar.xz
adventofcode2017-f6ecf88a2d9da1f140abedc52a0b9b46108a6563.zip
day19
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;
+}