about summary refs log tree commit diff
path: root/day06.cc
blob: f556f966c34379af11dff484c51a64a794a01c33 (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
#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;
}