about summary refs log tree commit diff
path: root/day06.cc
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-12-07 15:59:03 +0100
committerLeah Neukirchen <leah@vuxu.org>2017-12-07 15:59:03 +0100
commit2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e (patch)
tree992f9745449797e05d564dc2c63c94a76f6e1278 /day06.cc
parent89d3deb836bf6bb0f314e18755f7301517112198 (diff)
downloadadventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.tar.gz
adventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.tar.xz
adventofcode2017-2e09dc131e1c8fad8aac0e51fe4162ecdcf5194e.zip
day06
Diffstat (limited to 'day06.cc')
-rw-r--r--day06.cc24
1 files changed, 24 insertions, 0 deletions
diff --git a/day06.cc b/day06.cc
new file mode 100644
index 0000000..f556f96
--- /dev/null
+++ b/day06.cc
@@ -0,0 +1,24 @@
+#include <algorithm>
+#include <iostream>
+#include <iterator>
+#include <vector>
+#include <map>
+
+using namespace std;
+
+int
+main() {
+	map<vector<int>, int> seen;
+	int p1, i;
+
+	vector<int> v{istream_iterator<int>(cin), {}};
+
+	for (p1 = 0; seen.emplace(v, p1).second; p1++) {
+		auto m = max_element(begin(v), end(v));
+		for (i = *m, *m = 0; i-- > 0; ++*m)
+			if (++m == end(v))
+				m = begin(v);
+	}
+
+	cout << p1 << endl << p1 - seen[v] << endl;
+}