#include "aoc.h" namespace aoc2016 { 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 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