diff options
-rw-r--r-- | day25 | 62 | ||||
-rw-r--r-- | day25.cc | 43 | ||||
-rw-r--r-- | day25.k | 5 |
3 files changed, 110 insertions, 0 deletions
diff --git a/day25 b/day25 new file mode 100644 index 0000000..e2e4d56 --- /dev/null +++ b/day25 @@ -0,0 +1,62 @@ +Begin in state A. +Perform a diagnostic checksum after 12399302 steps. + +In state A: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state B. + If the current value is 1: + - Write the value 0. + - Move one slot to the right. + - Continue with state C. + +In state B: + If the current value is 0: + - Write the value 0. + - Move one slot to the left. + - Continue with state A. + If the current value is 1: + - Write the value 0. + - Move one slot to the right. + - Continue with state D. + +In state C: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state D. + If the current value is 1: + - Write the value 1. + - Move one slot to the right. + - Continue with state A. + +In state D: + If the current value is 0: + - Write the value 1. + - Move one slot to the left. + - Continue with state E. + If the current value is 1: + - Write the value 0. + - Move one slot to the left. + - Continue with state D. + +In state E: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state F. + If the current value is 1: + - Write the value 1. + - Move one slot to the left. + - Continue with state B. + +In state F: + If the current value is 0: + - Write the value 1. + - Move one slot to the right. + - Continue with state A. + If the current value is 1: + - Write the value 1. + - Move one slot to the right. + - Continue with state E. 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 +} diff --git a/day25.k b/day25.k new file mode 100644 index 0000000..5bdcc3a --- /dev/null +++ b/day25.k @@ -0,0 +1,5 @@ +/ d:`a`b`c`d`e`f!((1,1,`b;0,1,`c);(0,-1,`a;0,1,`d);(1,1,`d;1,1,`a);(1,-1,`e;0,-1,`d);(1,1,`f;1,-1,`b);(1,1,`a;1,1,`e)) + +d:`a`b`c`d`e`f!0N 2#+(1 0 0 0 1 1 1 0 1 1 1 1;1 1 -1 1 1 1 -1 -1 1 -1 1 1;`b`c`a`d`d`a`e`d`f`b`a`e) +v:20000#0;12399302{v[*x]::*s:d[*|x]v@*x;(s[1]+*x;s[2])}/10000,`a;+/v +\\ |