aboutsummaryrefslogtreecommitdiff
path: root/src/2016/day15/aoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/2016/day15/aoc.cpp')
-rw-r--r--src/2016/day15/aoc.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/2016/day15/aoc.cpp b/src/2016/day15/aoc.cpp
index e188291..318b345 100644
--- a/src/2016/day15/aoc.cpp
+++ b/src/2016/day15/aoc.cpp
@@ -2,5 +2,38 @@
namespace aoc2016 {
-std::pair<int64_t, int64_t> day15(line_view) { return {0, 0}; }
+size_t position_at(int t, int slot, size_t p) { return t > 0 ? (t % slot + p) % slot : p; }
+
+struct disc {
+ int slots;
+ size_t p;
+};
+
+static bool same(size_t* ps, int x) {
+ for (int i = 0; i < x; i++) {
+ if (ps[i] != ps[x]) {
+ return false;
+ }
+ }
+ return true;
+}
+
+int first_catch(disc ds[7], int x) {
+ int t{0};
+ while (true) {
+ size_t ps[7] = {0, 0, 0, 0, 0, 0, 0};
+ for (size_t i = 0; i < 7; i++) {
+ ps[i] = position_at(t + i + 1, ds[i].slots, ds[i].p);
+ }
+ if (same(ps, x)) {
+ return t;
+ }
+ t++;
+ }
+}
+
+std::pair<int64_t, int64_t> day15(line_view) {
+ disc ds[7] = {{17, 1}, {7, 0}, {19, 2}, {5, 0}, {3, 0}, {13, 5}, {11, 0}};
+ return {first_catch(ds, 5), first_catch(ds, 6)};
+}
} // namespace aoc2016