aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day6/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-14 22:42:10 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-14 22:42:10 +0800
commit5221877e962e70625921c2084c8a42996050aa94 (patch)
tree3f51aba7202744ca44ad6be24b18ee6b7125baed /src/2017/day6/aoc.cpp
parent9dcf63c0a3c8cfd0b1c1d6b335d38524775cd933 (diff)
downloadadvent-of-code-5221877e962e70625921c2084c8a42996050aa94.tar.gz
advent-of-code-5221877e962e70625921c2084c8a42996050aa94.zip
2016 2017 day6
Diffstat (limited to 'src/2017/day6/aoc.cpp')
-rw-r--r--src/2017/day6/aoc.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/2017/day6/aoc.cpp b/src/2017/day6/aoc.cpp
index 66511fd..c77e74f 100644
--- a/src/2017/day6/aoc.cpp
+++ b/src/2017/day6/aoc.cpp
@@ -3,7 +3,7 @@
namespace aoc2017 {
-void next(int* step, memory_bank& m, std::set<memory_bank>& ms) {
+void next(int* step, int* gap, memory_bank& m, std::set<memory_bank>& ms) {
if (ms.find(m) == ms.end()) {
ms.insert(m);
*step += 1;
@@ -11,16 +11,19 @@ void next(int* step, memory_bank& m, std::set<memory_bank>& ms) {
int i = m.highest(&d);
// printf("%d %d %d\n", *step, i, d);
m.distribute(i, d);
- next(step, m, ms);
+ next(step, gap, m, ms);
}
+ auto it = ms.find(m);
+ *gap = *step - it->index;
}
-int day6(line_view file) {
+std::pair<int, int> day6(line_view file) {
std::set<memory_bank> ms;
memory_bank m{file};
int steps{0};
- next(&steps, m, ms);
- return steps;
+ int gap{0};
+ next(&steps, &gap, m, ms);
+ return {steps, gap};
}
} // namespace aoc2017