aboutsummaryrefslogtreecommitdiff
path: root/src/2017/day6/aoc.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-04-14 22:07:42 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-04-14 22:07:42 +0800
commit9dcf63c0a3c8cfd0b1c1d6b335d38524775cd933 (patch)
treec629313107262f906a938139340f615b4ee2a479 /src/2017/day6/aoc.cpp
parentd94968612147691923e6b1dc5488414702f5ad8e (diff)
downloadadvent-of-code-9dcf63c0a3c8cfd0b1c1d6b335d38524775cd933.tar.gz
advent-of-code-9dcf63c0a3c8cfd0b1c1d6b335d38524775cd933.zip
2016 2017 day6 part1
Diffstat (limited to 'src/2017/day6/aoc.cpp')
-rw-r--r--src/2017/day6/aoc.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/2017/day6/aoc.cpp b/src/2017/day6/aoc.cpp
index ed2d9d3..66511fd 100644
--- a/src/2017/day6/aoc.cpp
+++ b/src/2017/day6/aoc.cpp
@@ -1,5 +1,26 @@
#include "aoc.h"
+#include <set>
namespace aoc2017 {
+void next(int* step, memory_bank& m, std::set<memory_bank>& ms) {
+ if (ms.find(m) == ms.end()) {
+ ms.insert(m);
+ *step += 1;
+ int d{0};
+ int i = m.highest(&d);
+ // printf("%d %d %d\n", *step, i, d);
+ m.distribute(i, d);
+ next(step, m, ms);
+ }
}
+
+int day6(line_view file) {
+ std::set<memory_bank> ms;
+ memory_bank m{file};
+ int steps{0};
+ next(&steps, m, ms);
+ return steps;
+}
+
+} // namespace aoc2017