aboutsummaryrefslogtreecommitdiff
path: root/2015/src/day10.cpp
blob: fe4686f3401610394a6b8b8b757b12abdabe0472 (plain)
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
#include <iostream>
#include <string>

using namespace std;

string
process(string_view str)
{
	string result{};
	size_t pos = 0;

	while ( pos != str.size() ) {
		char   cur   = str[pos];
		size_t count = 0;
		while ( pos != str.size() && cur == str[pos] ) {
			++count;
			++pos;
		}
		result += to_string(count);
		result += cur;
	}
	return result;
}

void
solve(string str, int n)
{
	for (int i = 0; i != n; ++i) {
		str = process(str);
	}
	cout << str.size() << endl;
}

int
main()
{
	solve("1113222113", 40);
	solve("1113222113", 50);
}