aboutsummaryrefslogtreecommitdiff
path: root/2015/src
diff options
context:
space:
mode:
Diffstat (limited to '2015/src')
-rw-r--r--2015/src/day10.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/2015/src/day10.cpp b/2015/src/day10.cpp
new file mode 100644
index 0000000..fe4686f
--- /dev/null
+++ b/2015/src/day10.cpp
@@ -0,0 +1,39 @@
1#include <iostream>
2#include <string>
3
4using namespace std;
5
6string
7process(string_view str)
8{
9 string result{};
10 size_t pos = 0;
11
12 while ( pos != str.size() ) {
13 char cur = str[pos];
14 size_t count = 0;
15 while ( pos != str.size() && cur == str[pos] ) {
16 ++count;
17 ++pos;
18 }
19 result += to_string(count);
20 result += cur;
21 }
22 return result;
23}
24
25void
26solve(string str, int n)
27{
28 for (int i = 0; i != n; ++i) {
29 str = process(str);
30 }
31 cout << str.size() << endl;
32}
33
34int
35main()
36{
37 solve("1113222113", 40);
38 solve("1113222113", 50);
39}