aboutsummaryrefslogtreecommitdiff
path: root/2025/src/day07.cpp
blob: ca73d879f86b1dce309872500568c4264816e0f3 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <filesystem>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

namespace {

vector<string>
read_file(const filesystem::path& filename)
{
	ifstream       file{ filename };
	vector<string> grid;

	for ( string line; getline(file, line); ) {
		grid.emplace_back(line);
	}

	return grid;
}

void
part1(const vector<string>& grid)
{
	set<size_t> curr;
	curr.insert(grid[0].find('S'));

	int count = 0;
	for ( size_t i = 1; i < grid.size(); ++i ) {
		const auto& row = grid[i];

		auto next = curr;

		for ( const auto pos: curr ) {
			if ( row[pos] == '^' ) {
				next.erase(pos);
				next.insert(pos - 1);
				next.insert(pos + 1);
				++count;
			}
		}

		curr = next;
	}
	cout << "Part 1: " << count << '\n';
}

} // namespace

int
main()
{
	auto grid = read_file("data/day07.txt");
	part1(grid);
}