about summary refs log tree commit diff
path: root/day11.cc
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-12 13:33:29 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-12 13:33:29 +0100
commit7ebb9a12f811f9b334815276621a2bdef391e917 (patch)
treefc1e01e7fc9cc1584264437f315301aed93d6abf /day11.cc
parentbc3f64835aca551f54cf2b2df86200d991b97a07 (diff)
downloadadventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.tar.gz
adventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.tar.xz
adventofcode2017-7ebb9a12f811f9b334815276621a2bdef391e917.zip
day11
Diffstat (limited to 'day11.cc')
-rw-r--r--day11.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/day11.cc b/day11.cc
new file mode 100644
index 0000000..9c51591
--- /dev/null
+++ b/day11.cc
@@ -0,0 +1,28 @@
+#include <algorithm>
+#include <iostream>
+#include <sstream>
+#include <string>
+#include <vector>
+
+using namespace std;
+
+int
+main() {
+	string sym;
+	int x{0}, y{0}, d{0}, maxd{0};
+
+	while (getline(cin, sym, ',')) {
+		if (cin.eof()) sym.pop_back();
+
+		if      (sym == "n" ) x--;
+		else if (sym == "s" ) x++;
+		else if (sym == "se")      y++;
+		else if (sym == "nw")      y--;
+		else if (sym == "ne") x--, y++;
+		else if (sym == "sw") x++, y--;
+
+		maxd = max(maxd, d = max({x,-x,y,-y,x+y,-x-y}));
+	}
+
+	cout << d << endl << maxd << endl;
+}