diff options
Diffstat (limited to '2025/src')
| -rw-r--r-- | 2025/src/day07.cpp | 58 |
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 | |||
| 8 | using namespace std; | ||
| 9 | |||
| 10 | namespace { | ||
| 11 | |||
| 12 | vector<string> | ||
| 13 | read_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 | |||
| 25 | void | ||
| 26 | part1(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 | |||
| 53 | int | ||
| 54 | main() | ||
| 55 | { | ||
| 56 | auto grid = read_file("data/day07.txt"); | ||
| 57 | part1(grid); | ||
| 58 | } | ||
