diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-12-17 16:56:26 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-12-17 16:56:26 +0100 |
commit | e3be85a6ed2e17e034d4686d85824238c547d61c (patch) | |
tree | 820b586c50f26eee19ccff1f4373ac6fee80966e /day16.cc | |
parent | 302fe6770b1e206964dafc265a38fdda405e61c0 (diff) | |
download | adventofcode2017-e3be85a6ed2e17e034d4686d85824238c547d61c.tar.gz adventofcode2017-e3be85a6ed2e17e034d4686d85824238c547d61c.tar.xz adventofcode2017-e3be85a6ed2e17e034d4686d85824238c547d61c.zip |
day16
Diffstat (limited to 'day16.cc')
-rw-r--r-- | day16.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/day16.cc b/day16.cc new file mode 100644 index 0000000..71851ee --- /dev/null +++ b/day16.cc @@ -0,0 +1,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; +} |