From c952634ddd6f24b4fd30f52d7b972764ae20d1b3 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Fri, 9 Dec 2022 08:50:22 +0100 Subject: day 9 part 2 --- 22.9/main.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to '22.9') 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 int main() { char dir; int steps; - Pos head{0,0}, tail{0,0}; - unordered_set visited; + Pos bridge[10] = {0}; + unordered_set visited1; + unordered_set 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; } -- cgit 1.4.1-2-gfad0