about summary refs log tree commit diff
path: root/day16.cc
blob: 71851ee214ae332a3049635795df138452fecab8 (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 <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>

using namespace std;

int
main() {
	string d;
	cin >> d;

	string s(16, ' ');
	iota(begin(s), end(s), 'a');
	
	map<string, int> seen;

        for (int p1 = 0; seen.emplace(s, p1).second; p1++) {
		char c;
		istringstream iss{d};
		while (iss >> c) {
			if (c == 's') {
				int r;
				iss >> r >> c;
				rotate(begin(s), end(s) - r, end(s));
			} else if (c == 'x') {
				int x, y;
				iss >> x >> c >> y >> c;
				swap(s[x], s[y]);
			} else if (c == 'p') {
				char x, y;
				iss >> x >> c >> y >> c;
				swap(s[s.find(x)], s[s.find(y)]);
			}
		}
	}

	for (auto &[k, v] : seen) if (v == 1) cout << k << endl;

	int n = 1'000'000'000UL % size(seen);
	for (auto &[k, v] : seen) if (v == n) cout << k << endl;
}