diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-25 15:34:43 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-25 15:34:43 +0100 |
commit | 1287f7d36af4cdbdc18194451538c09e800951ac (patch) | |
tree | 761b58d4bcf71f8de1ca92f4ac0bc40f8893c9cb /day25.cc | |
parent | 5c505911c9a0da95ae4bca311abc5902fbbcb1f3 (diff) | |
download | adventofcode2017-master.tar.gz adventofcode2017-master.tar.xz adventofcode2017-master.zip |
Diffstat (limited to 'day25.cc')
-rw-r--r-- | day25.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/day25.cc b/day25.cc new file mode 100644 index 0000000..f1eba65 --- /dev/null +++ b/day25.cc @@ -0,0 +1,43 @@ +#include <iostream> +#include <numeric> +#include <vector> + +using namespace std; + +struct trans; +using state = pair<trans,trans>; +struct trans { + int w, m; + state *n; +}; + +enum { + L = -1, + R = +1 +}; + +int main() { + int l = 12399302; + + state A, B, C, D, E, F; + A = {{1, R, &B}, {0, R, &C}}; + B = {{0, L, &A}, {0, R, &D}}; + C = {{1, R, &D}, {1, R, &A}}; + D = {{1, L, &E}, {0, L, &D}}; + E = {{1, R, &F}, {1, L, &B}}; + F = {{1, R, &A}, {1, R, &E}}; + + state *s = &A; + + vector<int> v(20'000, 0); + auto head = begin(v) + 10'000; + + for (int i = 0; i < l; i++) { + trans &t = *head == 0 ? s->first : s->second; + *head = t.w; + head += t.m; + s = t.n; + } + + cout << accumulate(begin(v), end(v), 0) << endl; // 2794 +} |