diff options
author | dzwdz | 2022-12-09 08:50:22 +0100 |
---|---|---|
committer | dzwdz | 2022-12-09 08:50:22 +0100 |
commit | c952634ddd6f24b4fd30f52d7b972764ae20d1b3 (patch) | |
tree | 47ecbb1d13c82c1b42903cd7e63fcd7e747d17ed /22.9/main.cpp | |
parent | 71e794fccb7c0a7f10ff9fb144bdffbc0fef41ad (diff) |
day 9 part 2
Diffstat (limited to '22.9/main.cpp')
-rw-r--r-- | 22.9/main.cpp | 17 |
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; } |