about summary refs log tree commit diff
path: root/day25.cc
blob: f1eba65cb86aaddda5d3f5d594fdf77302f13379 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
}