aboutsummaryrefslogtreecommitdiff
path: root/2025/src/day07.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2025-12-07 08:49:29 +0100
committerThomas Schmucker <ts@its1.de>2025-12-07 08:49:29 +0100
commite8f91f0bfb65fc6d2402e8f47270d2ae884ca724 (patch)
tree8768b415b47a66f57193603ef05d9846b0732c99 /2025/src/day07.cpp
parentc11df06541075ef464559adba1882b1f2ade2925 (diff)
downloadadvent-of-code-e8f91f0bfb65fc6d2402e8f47270d2ae884ca724.tar.gz
advent-of-code-e8f91f0bfb65fc6d2402e8f47270d2ae884ca724.tar.bz2
advent-of-code-e8f91f0bfb65fc6d2402e8f47270d2ae884ca724.zip
aoc 2025, day 7, part 1
Diffstat (limited to '2025/src/day07.cpp')
-rw-r--r--2025/src/day07.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/2025/src/day07.cpp b/2025/src/day07.cpp
new file mode 100644
index 0000000..ca73d87
--- /dev/null
+++ b/2025/src/day07.cpp
@@ -0,0 +1,58 @@
1#include <filesystem>
2#include <fstream>
3#include <iostream>
4#include <set>
5#include <string>
6#include <vector>
7
8using namespace std;
9
10namespace {
11
12vector<string>
13read_file(const filesystem::path& filename)
14{
15 ifstream file{ filename };
16 vector<string> grid;
17
18 for ( string line; getline(file, line); ) {
19 grid.emplace_back(line);
20 }
21
22 return grid;
23}
24
25void
26part1(const vector<string>& grid)
27{
28 set<size_t> curr;
29 curr.insert(grid[0].find('S'));
30
31 int count = 0;
32 for ( size_t i = 1; i < grid.size(); ++i ) {
33 const auto& row = grid[i];
34
35 auto next = curr;
36
37 for ( const auto pos: curr ) {
38 if ( row[pos] == '^' ) {
39 next.erase(pos);
40 next.insert(pos - 1);
41 next.insert(pos + 1);
42 ++count;
43 }
44 }
45
46 curr = next;
47 }
48 cout << "Part 1: " << count << '\n';
49}
50
51} // namespace
52
53int
54main()
55{
56 auto grid = read_file("data/day07.txt");
57 part1(grid);
58}