summary refs log tree commit diff
path: root/22.9
diff options
context:
space:
mode:
Diffstat (limited to '22.9')
-rw-r--r--22.9/main.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/22.9/main.cpp b/22.9/main.cpp
index 46cc68e..9e0ebca 100644
--- a/22.9/main.cpp
+++ b/22.9/main.cpp
@@ -51,8 +51,9 @@ struct std::hash<Pos>
 int main() {
 	char dir;
 	int steps;
-	Pos head{0,0}, tail{0,0};
-	unordered_set<Pos> visited;
+	Pos bridge[10] = {0};
+	unordered_set<Pos> visited1;
+	unordered_set<Pos> visited2;
 	while (scanf("%c %d ", &dir, &steps) == 2) {
 		Pos d;
 		switch (dir) {
@@ -63,10 +64,14 @@ int main() {
 			default: throw "bad input";
 		}
 		for (int i = 0; i < steps; i++) {
-			head = head.add(d);
-			tail = tail.moveTowards(head);
-			visited.insert(tail);
+			bridge[0] = bridge[0].add(d);
+			for (int j = 1; j < 10; j++) {
+				bridge[j] = bridge[j].moveTowards(bridge[j-1]);
+			}
+			visited1.insert(bridge[1]);
+			visited2.insert(bridge[9]);
 		}
 	}
-	cout << visited.size() << endl;
+	cout << visited1.size() << endl;
+	cout << visited2.size() << endl;
 }