aboutsummaryrefslogtreecommitdiff
path: root/2024
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2024-12-11 12:40:13 +0100
committerThomas Schmucker <ts@its1.de>2024-12-11 12:40:13 +0100
commit585d3537ed50602ae706be1ed9b7bb59a4a98976 (patch)
treed9a1a60944c6d050e8fda6e5fe256bed8183969b /2024
parentfef2d224ed2e53e5b33e030f06491b43047bbbe2 (diff)
downloadadvent-of-code-585d3537ed50602ae706be1ed9b7bb59a4a98976.tar.gz
advent-of-code-585d3537ed50602ae706be1ed9b7bb59a4a98976.tar.bz2
advent-of-code-585d3537ed50602ae706be1ed9b7bb59a4a98976.zip
aoc 2024, day 11, part 1
Diffstat (limited to '2024')
-rw-r--r--2024/src/day11.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/2024/src/day11.cpp b/2024/src/day11.cpp
new file mode 100644
index 0000000..f31e30b
--- /dev/null
+++ b/2024/src/day11.cpp
@@ -0,0 +1,45 @@
1#include <fstream>
2#include <iostream>
3#include <iterator>
4#include <vector>
5using namespace std;
6
7vector<long>
8read_file(string_view filename)
9{
10 fstream input{ filename };
11 return { istream_iterator<long>{ input }, {} };
12}
13
14void
15part1(vector<long> data)
16{
17 for ( size_t i = 0; i != 25; ++i ) {
18 vector<long> temp;
19 for ( const auto value: data ) {
20 if ( value == 0 ) {
21 temp.push_back(1);
22 continue;
23 }
24
25 auto str = to_string(value);
26 if ( str.size() % 2 == 0 ) {
27 auto len = str.size() / 2;
28 temp.push_back(stol(str.substr(0, len)));
29 temp.push_back(stol(str.substr(len)));
30 continue;
31 }
32
33 temp.push_back(value * 2024);
34 }
35 data.swap(temp);
36 }
37 cout << data.size() << endl;
38}
39
40int
41main()
42{
43 auto data = read_file("data/day11.txt");
44 part1(data);
45}